No console output on cout

故事扮演 提交于 2019-11-28 03:55:49

问题


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. e.g.:
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!


回答1:


You need to end output strings with newline, e.g.: `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).




回答2:


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);



回答3:


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.




回答4:


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;*



回答5:


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)




回答6:


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.




回答7:


try outputting a space at the beginning of each line

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



来源:https://stackoverflow.com/questions/4591915/no-console-output-on-cout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!