acm的输入文件和输出文件方法

#include <iostream>
#include <cstdio>   //freopen函数在这个文件中
using namespace std;  //这里是从文件读入,写到文件output中(屏幕没有显示,因为改变了输出流)
int main()
{
	#ifndef ONLINE_JUDGE    //if not define 如果没有定义这个的话就执行下面
	freopen("input.txt", "r", stdin);   //只改变输入流的文件指针,读入这个文件的内容(必须要有input这个文件)stdin是标准输入流的文件指针
	freopen("output.txt", "w", stdout);  //只改变输出流的文件指针,写入output内(如果没有output这个文件就会自动生成)stdout是标准输出流的文件指针
	#endif
	int a, b;
	while(cin>>a>>b)
		cout<<a+b<<endl;
	return 0;
}





#include <iostream>
#include <cstdio>
using namespace std;   //这里是从文件读入,从显示屏输出,因为原本的输出流没有改变
int main()
{
	#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	int a, b;
	while(cin>>a>>b)
		cout<<a+b<<endl;
}







#include <iostream>
#include <cstdio>
using namespace std;   //这里是从屏幕读入,写入文件中(不在屏幕显示),因为原本的输入流没有改变
int main()
{
	#ifndef ONLINE_JUDGE 
	freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	int a, b;
	while(cin>>a>>b)
		cout<<a+b<<endl;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值