unable to see the output of c++ program in the con

2019-04-03 00:06发布

I have installed the eclipse ide(cdt) on my windows 8 laptop and tried writing a simple c program to check whether the program executes.

It did not execute and gave the error : binary not found .

So I did some searching online and realized that my system did not have a c/c++ compiler installed.
So I installed MinGW and selected the c and c++ compilers during installation.
Then I set the PATH environment variable to C:\MinGW.
I reopened eclipse, wrote a simple c program and it worked as expected!

I created a c++ project, wrote a simple piece of code and could not see the output in the console!

Here is the code:

#include<iostream>
using namespace std;

int main()
{
    cout<<"sample text";
    return 0;
}

2条回答
我只想做你的唯一
2楼-- · 2019-04-03 00:11

You may simply need to flush the output, using flush or endl. Try this:

cout<<"sample text" << endl;

or

cout<<"sample text" << flush;
查看更多
Deceive 欺骗
3楼-- · 2019-04-03 00:24

Linker (Option) > Add Command (g++ -static-libgcc -static-libstdc++)

This is not the right solution.

You have in your path environment variable only c:\minGW .
But it should be c:\minGW;c:\minGW\bin . (Set the PATH before open eclipse)

Therefore, libstdc++-6.dll needed by the current program, can not be found.

In eclipse there is no error, but no output in the console !!

It to compile into the program may be regarded as a trick, but will only work for the standard libs .


your linker flags should not be set like :

--> MinGW C++ Linker (Option) > Command (g++ -static-libgcc -static-libstdc++)

should be set here :

enter image description here


I know in this case it is not necessary at the end << endl to write.
A good programming style should use << endl :

cout << "sample text" << endl;
查看更多
登录 后发表回答