<分区>
我希望 cout
打印“hello”,两秒后打印“world”。
int t = time( NULL );
std::cout << "hello";
while( time(NULL) < (t + 2) );
std::cout << " world";
但是,cout
会在两秒后将注释打印到屏幕上,然后程序会打印“hello world”。即使像(t + 9)
这样增加时间延迟,也是一样的结果。我不熟悉这种 cout
行为。
但是如果我像这样在第一个 cout
处添加 std::endl
:
std::cout << "hello" << std::endl;
...
我得到预期结果“hello”,两秒后得到“world”。