去除文件中重复的字符串

摘自: www.chinaitlab.com  被阅读次数: 104


yangyi 于 2009-07-03 23:01:48 提供


 #include <iostream>
#include <fstream>
#include <set>
#include <string>
#include <iterator>
#include <algorithm>

using namespace std;

int main()
{
    string      line;
    set<string> uniq_set;
    ifstream    infile("pathname");

    istream_iterator<string> inbeg(infile), inend;
    copy( inbeg, inend, inserter(uniq_set, uniq_set.begin()) );

    infile.close();
    ofstream outfile("pathname");

    copy( uniq_set.begin(), uniq_set.end(), ostream_iterator<string>(outfile, "\n") );
}

原文链接: http://c.chinaitlab.com/cc/basic...