(一)重定向版
#define LOCAL //测试时加上,如果程序没有要求读写文件则注释掉
#include<iostream>
#include<string>
#include<cstring>
#include<Windows.h>
#include<cmath>
using namespace std;
int main()
{
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
//下面是常规操作
system("pause");
return 0;
}
(二)fopen版
#include<iostream>
#include<string>
#include<cstring>
#include<Windows.h>
#include<cmath>
using namespace std;
int main()
{
int in, out;
FILE *fin, *fout;
fin = fopen("data.in", "rb"); //fin用作文件读入
fout = fopen("data.out", "wb"); //fout用作文件写出
fscanf(fin, "%d", &in); //读入文件的内容
out = in;
fprintf(fout, "%d", out);//写出文件的内容
system("pause");
return 0;
}