比如说有一道文件读写的a+b
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
freopen("aplusb.in", "r", stdin);
freopen("aplusb.out", "w", stdout);
cin >> a >> b;
cout << a + b;
return 0;
}
这么写也能过
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
ifstream fin("aplusb.in");
ofstream fout("aplusb.out");
fin >> a >> b;
fout << a + b;
return 0;
}
或者这样也行
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
ifstream ccf("aplusb.in");
ofstream gesp("aplusb.out");
ccf >> a >> b;
gesp << a + b;
return 0;
}
总结
文件读写只要是文件读写就行,无所谓方式,但是由于freopen更加方便,所以没人用ifstream、ofstream
