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