读取一个文件,然后排序,再写入另一个文件

读取一个文件,然后排序,再写入另一个文件 ,文件名: filereadandwrite.cpp

 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.
";
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, "
");
27  copy(text.begin(), text.end(), os);
28  
29  system("pause");
30  
31 }
原文地址:https://www.cnblogs.com/xiejh/p/5155677.html