合并两个单词列表

Sha*_*aez 1 c c++ merge

我想将两个单词列表合并到一个文件中.必须删除所有重复项.每个单词都用换行符分隔.我已经搜索过这种程序,但我找不到任何东西.我在寻找合适的东西吗?这有ac/c ++实现吗?

Pot*_*ter 8

// read input
std::ifstream in( file_path );
typedef std::set< std::string > wordlist_type;
wordlist_type wordlist;
std::string word;

while ( in >> word ) {
    wordlist.insert( word );
}

// repeat with other files to merge more wordlists

// now output to a new file
std::ofstream out( output_path );
for ( wordlist_type::iterator it = wordlist.begin(); it != wordlist.end(); ++ it ) {
    out << * it << '\n';
}
Run Code Online (Sandbox Code Playgroud)