#include <iostream>
#include <cstdlib>
#include <sstream>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
using std::string;
int dofile() {
string ifile;
string ofile;
cout << "input the file we read from:" << endl;
cin >> ifile;
cout << "input the file we write to:" << endl;
cin >> ofile;
ifstream infile;
ofstream outfile;
infile.open(ifile.c_str());
outfile.open(ofile.c_str());
if (!infile) {
cerr << "error: unable to open input file: "
<< ifile << endl;
return -1;
}
if (!outfile) {
cerr << "error: unable to open output file: "
<< ofile << endl;
return -1;
}
/*
string line;
while (getline(infile, line)) {
outfile << line << endl;
}
*/
string word;
while (infile >> word) {
outfile << word << flush;
}
outfile.close();
infile.close();
return 0;
}
int main() {
return dofile();
}
C++学习代码--file
最新推荐文章于 2024-09-11 19:54:50 发布