使用stdio.h来进行读写
1 #include <cstdio>
2
3 using namespace std;
4
5 int main()
6 {
7 FILE *fin, *fout;
8 fin = fopen("test.in", "rb");
9 fout = fopen("test.out", "wb");
10 int t;
11
12 while (fscanf(fin, "%d", &t))
13 fprintf(fout, "%d ", t);
14 fclose(fin);
15 fclose(fout);
16 return 0;
17 }
使用fstream来进行读写
1 #include <iostream>
2 #include <fstream>
3
4 using namespace std;
5
6 int main()
7 {
8 ifstream fin("test.in");
9 ofstream fout("test.out");
10 int t;
11
12 while (fin >> t)
13 fout << t << " ";
14 fin.close();
15 fout.close();
16 return 0;
17 }
设置不与stdio同步,可以提高读写速度
std::ios::sync_with_stdio(false);
原文链接: https://www.cnblogs.com/anarch/archive/2012/12/08/2809145.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/71863
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!