Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

c++ - 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. 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...
";
    cout << "
" << "Programm closed...

";
    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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...