set有问题!
- C/C++ code
#include <fstream>#include <set>#include <string.h>#include <iostream>#include <stdlib.h>using namespace std;void doit(){ ifstream infile("D:\\mobilelist.txt"); ofstream outfile("D:\\Mobile.txt"); set<char *> lines; char tmp[150]; lines.insert("hello!"); while(infile) { infile.getline(tmp, 145, '\n'); if(lines.find(tmp) == lines.end()) { lines.insert(tmp); cout<<"insert"<<endl; } else { continue; } for(set<char *>::const_iterator it= lines.begin(); it != lines.end(); it++) { outfile<<*it<<"\r\n"; } } infile.close(); outfile.close();}int main(){ doit(); system("pause"); return 0;}
D:\\mobilelist.txt中有各种手机地址,类似:http://product.tech.163.com/mobile/这样的,一行一个地址.但是有相同的,我想去除相同的,但是问题是 lines.insert(tmp);只插入一次,后边就不插入了,不知道什么原因.高手指点!
[解决办法]
set中的char *改成用string