RT。
我曾在某个帖子里发表过如下言论(已删):
ios::sync_with_stdio(0) 不能和 freopen 一起用。
前几天考试的时候我试验了一下,发现关同步是可以和 freopen 一起用的,但是一旦 fclose 输出文件就什么也没有了。(如下:)
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
freopen("1.txt","w",stdout);
ios::sync_with_stdio(0);
for(int i=1;i<=10;++i)cout<<"CSP2022 RP++"<<'\n';
fclose(stdout);
return 0;
}
而 fclose 和关闭同步当中任意关掉一个就没有问题了。
有无大佬知道原因/kel(我问了教练的说法好像是缓冲区不一样?)