1 #include <iostream> 2 #include <fstream> 3 #include <iterator> 4 #include <algorithm> 5 #include <vector> 6 #include <string> 7 using namespace std; 8 9 int main() { 10 ifstream in_file("input_file.txt"); 11 ofstream out_file("output_file.txt"); 12 13 if(! in_file || ! out_file) { 14 cerr << "!! unable to open the necessary files.\n"; 15 return -1; 16 } 17 18 istream_iterator<string> is(in_file); 19 istream_iterator<string> eof; 20 21 vector<string> text; 22 copy(is, eof, back_inserter(text)); 23 24 sort(text.begin(), text.end()); 25 26 ostream_iterator<string> os(out_file, "\n"); 27 copy(text.begin(), text.end(), os); 28 29 system("pause"); 30 31 }
时间: 2024-10-08 17:22:08