其他:OI竞赛中的文件操作
2024-09-02 03:47:39
本文介绍三种方法进行文件输入输出,都非常实用
第一种方法是采用重定向的形式进行输入输出,很方便
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选手推荐使用第一种方式
最新文章
- sp_who使用
- get请求
- linux-菜鸟新手命令(1)
- 30.赋值运算符重载函数[Assign copy constructor]
- [转]漫谈数据中心CLOS网络架构
- CCNU-线段树练习题-A-单点更新1
- SQL2005/8数据库提示单个用户无法操作的解决方法
- Android:删除模拟器中没用的应用
- poj 动态规划的主题列表和总结
- Pointers to classes (From the note of my firend)
- php 图片压缩处理
- Dockerfile 最佳实践
- 洛谷 P2194 HXY烧情侣【Tarjan缩点】 分析+题解代码
- 第64节:Java中的Spring Boot 2.0简介笔记
- Go语言之闭包
- 补充:ajax PHP html js 实现 三级联动(省 市 区)
- vue 监听store中的数值
- Codeforces Round #492 (Div. 2)
- [转]SSIS中的脚本—脚本任务
- Fireworks层与蒙版的概念和用法