去除文件中重复的字符串
本程序假设文件中的字符串以空白(空格、tab 和换行)隔开。如果文件内容为: string vvv http string vvv stdcpp.cn stdcpp cn
stdcpp.cn string cvs
hvp
则输出为 cn
cvs
http
hvp
stdcpp
stdcpp.cn
string
vvv 功能:去除文件中重复的字符串,并将结果按字符串大小顺序输出
stdcpp.cn string cvs
hvp
则输出为 cn
cvs
http
hvp
stdcpp
stdcpp.cn
string
vvv 功能:去除文件中重复的字符串,并将结果按字符串大小顺序输出
#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") );
}
顶(0)
踩(0)
上一篇:C++虚拟函数实现多态性分析
下一篇:基础入门:解密数组名本质
- 最新评论
