1 #include <iostream> 2 #include <set> 3 #include <fstream> 4 #include <string> 5 using namespace std; 6 7 int main() 8 { 9 set <string> s; 10 string str; 11 ifstream in("source.txt"); 12 ofstream out("result.txt"); 13 14 while(getline(fin,str)) //按行读取 15 { 16 s.insert(str); 17 } 18 19 for(set<string>::iterator it=s.begin(); it!=s.end(); ++it) 20 out < <*it < <"\n"; //按行输出 21 22 in.close(); 23 out.close(); 24 25 return 0; 26 }
转载于:https://www.cnblogs.com/kevinGaoblog/archive/2012/07/18/2598246.html