cout上没有控制台输出 [英] No console output on cout
问题描述
早上好,
我有一个针对C / C ++开发人员的Eclipse IDE问题。
写一个smal工具转换字符串。虽然在某些点测试 eclipse停止给予控制台输出。
例如:
cout<<test;
不显示。 >
但它不是每个地方...另一个例子:
路径作为参数
int main(int argc,char * argv []){
if(argc!= 2){
cout
& 错误:参数数量错误!只有一个允许... \\\
;
cout<< \\\
< 程序关闭... \\\
\\\
;
exit(1);
}
CommandConverter a(argv [1]);
cout<<test;
a.getCommandsFromCSV();
cout<<test2;
return 0;
}
如果参数丢失,错误消息正确显示。
但是如果参数存在并且程序继续测试输出:
cout< >
cout<<test2;
不显示...
您需要使用换行符结束输出字符串,例如:`cout< test\\\
``。原因是标准输出被缓冲,并且缓冲区在换行符上被刷新。可能存在一种方法来刷新cout缓冲区,而不输出换行符,但我不知道它的心。可能包括访问底层的streambuf(通过rdbuf方法)。
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!
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).
这篇关于cout上没有控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!