這句語句是用來取消cin的同步,什么叫同步呢?就是iostream的緩沖跟stdio的同步。如果你已經在頭文件上用了using namespace std;那么就可以去掉前面的std::了。取消后就cin就不能和scanf,sscanf, getchar, fgets之類同時用了,否則就可能會導致輸出和預期的不一樣。
#include <iostream> #include <cstdio> using namespace std; int main() { cout.sync_with_stdio(false); cout << "a\n"; printf("b\n"); cout << "c\n"; } 輸出結果是 b a c
取消同步的目的,是為了讓cin不超時,另外cout的時候盡量少用endl,換用"\n",也是防止超時的方法。
當然,盡量用scanf,printf就不用考慮這種因為緩沖的超時了。