gpt4 book ai didi

c++ - cout 不产生输出

转载 作者:太空宇宙 更新时间:2023-11-04 11:57:26 28 4
gpt4 key购买 nike

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

#include <iostream>
#include <stdio.h>

Object::Method()
{
printf("why is the next line not printing? This one prints fine\n");

std::cout << "This line should print second, but doesnt" << std::endl;

printf("but this line prints fine like the first!\n");
}

输出是:

why is the next line not printing? This one prints fine

but this line prints fine like the first!

我似乎无法弄清楚为什么它不会打印。 std::flush 也没有效果。

最佳答案

您应该继续使用 std::cout(C++ 流)或 C 风格的流。混合它们可能会产生未定义的行为。

例如,它们可以有单独的“缓冲” channel 。

关于c++ - cout 不产生输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15588821/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com