1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #include <iostream> #include <fstream> #include <sstream> #include <stdexcept> using namespace std; int main(int argc, char *argv[]) { if(argc != 3){ string err_info; ostringstream oss(err_info); oss << argv[0] << " dir1/file1 dir2/file2" << endl; cerr << oss.str(); return -1; } string in = argv[1]; string out = argv[2]; string content; ifstream ifs(in.c_str()); ofstream ofs(out.c_str()); if (!ifs) { cerr << "error: unable to open input file: " << in << endl; return -1; } if (!ofs) { cerr << "error: unable to open output file: " << out << endl; return -1; } while(getline(ifs, content)){ ofs << content << endl; } }
|