简体   繁体   中英

No console output on cout

Good morning,

I have a problem with Eclipse IDE for C/C++ Developers.

I'm writting a smal tool for converting Strings. While testing on some point eclipse stopped to give console output . eg:
cout<<"test";
doesn't get displayed.

But it's not every where... another example:

// File path as argument
int main(int argc, char* argv[]) {
if (argc != 2) {
    cout
            << "ERROR: Wrong amount of arguments! Only one allowed...\n";
    cout << "\n" << "Programm closed...\n\n";
    exit(1);
}

CommandConverter a(argv[1]);
cout<<"test";
a.getCommandsFromCSV();
cout<<"test2";

return 0;
}

The error message is displayed correctly if the argument is missing. But if the argument is there and the program continues the test outputs:

cout<<"test";
cout<<"test2";

are not displayed...
I am missing something obvious?

Thanks in advance!

You need to end output strings with newline, eg: `cout << "test\n"``. The reason is that the standard output is buffered and the buffer is flushed on newline. There probably exists a way to flush the cout buffer without outputting a newline, but I don't know it by heart. Probably includes access to the underlying streambuf (via the rdbuf method).

For me installing the 32 bit versions of Eclipse (Indigo 3.7) and the 32 bit Java JDK/JRE did not work. I use the much quicker solution from the Eclipse CDT/User/FAQ :

Quote from Eclipse CDT/User/FAQ - Eclipse console does not show output on Windows :

Eclipse console does not show output on Windows In Eclipse CDT on Windows, standard output of the program being run or debugged is fully buffered, because it is not connected to a Windwos console, but to a pipe. See bug 173732 for more details. Either add fflush calls after every printf or add the following lines in the start of the main function:

 setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0);

I had a similar problem. In my case the program would give output if run from the command line but not from eclipse console. The solution was to use the 32 bit version of eclipse and not the 64 bit one.

I read that it was a bug. Might not be the same issue though.

This Happens when you debug your code and dont see the output till the last. use

cout<<"what ever overloads"<< flush;

to see the output immediately on stdout(console)

I was also searching for exactly this information when I found this on the Microsoft website http://support.microsoft.com/kb/94227

I think a simple method is to use std::flush when you want to force flushing the internal buffer that cout uses

*std::cout << ... << std::flush;*

Hi after some similar struggle I figured out, that the first element of the project's properties environment PATH variable must be "C:\MinGW\bin;" Otherwise a wrong version might be used, especially if you use different compiler.

try outputting a space at the beginning of each line

cout << " " << .....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM