Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 786
Gqqnbig Avatar asked May 11 '11 06:05

Gqqnbig


People also ask

How do I display output in Eclipse?

Inside Eclipse -> Click on "Window" Select "Show View" Then select "Console" If you cannot see console in the list, select "Other" and then search for "console' in new dialog at top and select "Console"

Why console is empty in eclipse?

If eclipse is not showing path, Please click on RUN-> Run configuration->click on environment tab->click on New-> add a path variable as mingw_path(if compiler is mingw in case of c++ ) and set value as C:\MinGw\bin (please check ur mingw bin path then only set).


1 Answers

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.
like image 153
Vikyboss Avatar answered Sep 16 '22 19:09

Vikyboss