0
clock_t tStart = clock();
ios::sync_with_stdio(0);
cin.tie(0);
for(int i=0;i<100000;++i) cout<<i;
printf("\n\n\n\nTime taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
cout<<endl;
使用此程序與cout運行在4.05秒,但輸出一些數字,即使它執行最後一行。這裏的細節:當使用'ios :: sync_with_stdio(0)'測試運行時的差異時,爲什麼我的輸出是分段的?
Time taken: 4.30s
99924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999
使用printf程序按預期運行,但非常慢(51秒)。打印時間後我使用了endl來刷新輸出緩衝區。這是什麼原因?
爲什麼混合'printf'和'cout'呢? – AndyG