Beverly 2008-10-3 18:33
acm技巧 使用文件输入输出方便测试的方法
把下面两块宏语句分别嵌在main函数的开始和结束,这样在本地调试的时候,cin/cout和scanf/printf直接对应到指定的文件流,但提交到OJ时,此两句不被编译,所以仍为标准I/O流,因此不用提交前改代码。
后面一块宏不用也可以,前面一块宏根据自己的输入文件改变"in.txt","out.txt",也可以只用其一。
#include <iostream>
#include <cstdio>
using namespace std;
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
用这种方法,cin/cout和scanf/printf都可以转化为文件流