测试数据文件:
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include <iostream>
using namespace std;
int main(void)
{
freopen("in.txt","w",stdout);
srand(time(NULL));
int n=1000;//测试数据数量
while(n--)
{
cout<<rand()%1000<<" "<<rand()%1000<<endl;
//printf("%d\n",rand());
}
fclose(stdout);
return 0;
}
标准程序:
//#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int a,b;
freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
freopen("out1.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
while(cin>>a>>b){
cout<<a+b<<endl; // 注意使用endl
}
fclose(stdin);//关闭文件
fclose(stdout);//关闭文件
return 0;
}
测试程序:
//#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int a,b;
freopen("in.txt","r",stdin); //输入重定向,输入数据将从in.txt文件中读取
freopen("out2.txt","w",stdout); //输出重定向,输出数据将保存在out.txt文件中
while(cin>>a>>b){
if(a<5)
cout<<a+b<<endl; // 注意使用endl
else
cout<<a*b<<endl;
}
fclose(stdin);//关闭文件
fclose(stdout);//关闭文件
return 0;
}
创建bat文件,输入
fc out1.txt out2.txt
pause