C++ program written in Eclipse using Windows and MinGW cannot display output to console view

cconsoleeclipseeclipse-cdt

I'm using Windows 7 64bit.

I installed eclipse version 3.6.2, cdt, and MinGW. I have a C++ console program in Eclipse as follows:

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    setbuf(stdout, NULL);

    for (int i = 0; i < 10000000; i++) {
        cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    }
    int val;
    cin >> val;

    return 0;
}

If I run this console program, it should display Hello world to Console View in Eclipse, but nothing displays.

If I go to the debug folder and run the exe, it does print to the console.

If I make some syntax mistake, then the Eclipse Console View will show something, such as:

**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\hh.o ..\src\hh.cpp
..\src\hh.cpp: In function 'int main()':
..\src\hh.cpp:17:3: error: expected ';' before 'return'
Build error occurred, build is stopped
Time consumed: 255 ms.   

Why is nothing showing in the Eclipse console view and how can I make my C++ console program display output?

Best Answer

I found a workaround from this site: http://www.eclipse.org/forums/index.php?=42e862594001fa4469bbc834885d545f&t=msg&th=197552

At that link, look at the reply from "No real Name".

In case the link goes down, here is the content:

Environment: jdk1.6u18 64bit + Eclipse Helios 64bit + win7 64bit

No console output at "Run", but output correctly at "Debug".

The following method worked for me:

1.  Goto Project->Properties->Run/Debug Settings, choose the .exe file 
and press "Edit"

2.  In the "Environment" tag, press "New", set it as: 
    "Name:PATH"
    "Value:C:\MinGW\bin"

In fact, I have already set "C:\MinGW\bin" in windows PATH environment 
variable, but it seemed to not work.
Related Topic