我希望cout
打印“hello”,两秒钟后打印“world”。
int t = time( NULL );
std::cout << "hello";
while( time(NULL) < (t + 2) );
std::cout << " world";
但取而代之的cout
是,直到两秒钟后才打印到屏幕上,然后程序打印“hello world”。即使时间延迟增加(t + 9)
,结果也是一样的。我不熟悉这种cout
行为。
但是,如果我像这样std::endl
首先添加:cout
std::cout << "hello" << std::endl;
...
我得到了预期的结果“你好”,两秒钟后得到了“世界”。