+
95
-

回答

这是由于cout的缓存造成了,有两种办法

第一、强制缓存输出

std::cout << "test" << std::flush; // std::flush is in <iostream>

std::cout << "test";
std::cout.flush(); // explicitly flush here

std::cout << "test" << std::endl; // endl sends newline char(s) and then flushes

第二种、不缓存

std::setvbuf(stdout, NULL, _IONBF, 0);

或运行c++程序的时候加入以下参数

stdbuf -o 0 ./yourprogram --yourargs


网友回复

我知道答案,我要回答