本文介绍三种方法进行文件输入输出,都非常实用

第一种方法是采用重定向的形式进行输入输出,很方便

freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);

记得包含头文件#include<cstdio>

第二种方法是使用C语言的形式进行输入输出

 #include<cstdio>
#define INF 1000000000
using namespace std;
int main()
{
FILE *fin,*fout;
fin=fopen("input.txt","rb");
fout=fopen("output.txt","wb");
int a,b;
fscanf(fin,"%d%d",&a,&b);
fprintf(fout,"%d\n",a+b);
return ;
}

第三种方法是C++推荐的形式,以流的形式输入输出

 #include<fstream>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int main()
{
int a,b;
in>>a>>b;
out<<a+b;
return ;
}

OI选手推荐使用第一种方式

最新文章

  1. sp_who使用
  2. get请求
  3. linux-菜鸟新手命令(1)
  4. 30.赋值运算符重载函数[Assign copy constructor]
  5. [转]漫谈数据中心CLOS网络架构
  6. CCNU-线段树练习题-A-单点更新1
  7. SQL2005/8数据库提示单个用户无法操作的解决方法
  8. Android:删除模拟器中没用的应用
  9. poj 动态规划的主题列表和总结
  10. Pointers to classes (From the note of my firend)
  11. php 图片压缩处理
  12. Dockerfile 最佳实践
  13. 洛谷 P2194 HXY烧情侣【Tarjan缩点】 分析+题解代码
  14. 第64节:Java中的Spring Boot 2.0简介笔记
  15. Go语言之闭包
  16. 补充:ajax PHP html js 实现 三级联动(省 市 区)
  17. vue 监听store中的数值
  18. Codeforces Round #492 (Div. 2)
  19. [转]SSIS中的脚本—脚本任务
  20. Fireworks层与蒙版的概念和用法

热门文章

  1. js经典试题之数组与函数
  2. LVS+Keepalive+Nginx实现负载均衡
  3. 软件工程-东北师大站-第二次作业psp
  4. Daily Scrum8
  5. 最长回文子串计算(fail)
  6. Java中ArrayList与数组间相互转换
  7. Java内存区域划分和GC机制
  8. “小葵日记”API接口文档
  9. C/C++打印堆栈信息
  10. 用css制作空心箭头(上下左右各个方向均有)