cout 上没有控制台输出

No console output on cout(cout 上没有控制台输出)
本文介绍了cout 上没有控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

早上好,

我对 C/C++ 开发人员的 Eclipse IDE 有疑问.

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

我正在编写一个用于转换字符串的小工具.在某个点进行测试时 eclipse 停止提供控制台输出.例如:
cout<<"test";
不显示.

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<<"测试";
cout<<"test2";

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

不显示...
我遗漏了一些明显的东西?

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

提前致谢!

推荐答案

你需要用换行符结束输出字符串,例如:`cout <<测试 "``.原因是标准输出被缓冲并且缓冲区在换行时被刷新.可能有一种方法可以在不输出换行符的情况下刷新 cout 缓冲区,但我不知道.可能包括对底层流缓冲区的访问(通过 rdbuf 方法).

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

这篇关于cout 上没有控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

egit plugin for Eclipse(Eclipse 的 egit 插件)
Gitlab cannot open git-upload-pack error(Gitlab 无法打开 git-upload-pack 错误)
How to add GitLab repository in Eclipse?(如何在 Eclipse 中添加 GitLab 存储库?)
Eclipse#39;s Visual Studio Ctrl+Tab and Ctrl+Shift+Tab Equivalent(Eclipse 的 Visual Studio Ctrl+Tab 和 Ctrl+Shift+Tab 等效项)
How to prevent Eclipse from showing the opened file in package explorer(如何防止 Eclipse 在包资源管理器中显示打开的文件)
Iterators in C++ (stl) vs Java, is there a conceptual difference?(C ++(stl)与Java中的迭代器,有概念上的区别吗?)