cout不产生输出

cout does not produce output

本文关键字:输出 cout      更新时间:2023-10-16

所以我在一个对象的方法中,但cout语句根本不产生输出。

#include <iostream>
#include <stdio.h>
Object::Method()
{
    printf("why is the next line not printing? This one prints finen");
    std::cout << "This line should print second, but doesnt" << std::endl;
    printf("but this line prints fine like the first!n");
}

输出为:

为什么下一行没有打印?这张打印出了很好的

但这一行打印得和第一行一样好!

我似乎不明白为什么它不会印刷。CCD_ 1也没有作用。

您应该使用std::cout(C++流(或C样式流。将它们混合可能会产生未定义的行为。

例如,它们可以有单独的"缓冲"通道。

代码片段在我的系统上运行良好,您的问题可能来自此处未列出的代码的其他部分。尝试在方法的开头使用fflush(stdout),看看它是否有效。