essential c++ source code part 1

#include <iostream>
#include <fstream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main()
{
    ifstream in_file("a.txt");
    ofstream out_file("b.txt");

    if (!in_file || !out_file) {
        cout << "unable to open file" << endl;
        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, " ");
    copy(text.begin(), text.end(), os);
}

猜你喜欢

转载自www.cnblogs.com/pfsi/p/9149076.html