freopen可以代替在黑框中的输入输出
#include<bits/stdc++.h>
using namespace std;
int main(){
freopen("1.in.txt","r",stdin);
freopen("1.out.txt","w",stdout);
int a,b;
cin>>a>>b;
cout<<a<<b;
fclose(stdin);
fclose(stdout);
return 0;
}
freopen()中的文件1.in.txt和1.out.txt要跟主文件在同一个目录下。
fclose()有两个好处:
(1)将缓存区中的内容立刻刷到磁盘文件里,避免文件没有写入;
(2)释放文件指针。