从文件中读取内容,进行排序并输出
#include <iostream>
#include <vector>
#include <functional>
#include <fstream>
#include <iterator>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
ifstream in_file("input_file.txt");
ofstream out_file("output_file.txt");
if (!in_file || !out_file)
{
cerr << "unable to open the necessary files.\n";
return -1;
}
istream_iterator<string> is(in_file);
istream_iterator<string> eof;
vector<string> text;
copy(is, eof, back_inserter(text));
sort(text.begin(), text.end());
ostream_iterator<string> os(out_file, " ");
ostream_iterator<string> os2(cout, " ");
copy(text.begin(), text.end(), os);
copy(text.begin(), text.end(), os2);
}