有一个包含名称的文本文件:
Jack Sparrow
David Linch
Jack Sparrow
Umble Gamble
Lee Sion
Truman Bruman
Lee Sion
我尝试使用<set>
从中删除重复项,但问题是它会自动排序。我想这样做而不进行分类。
这是我的代码:
int main()
{
string name;
set <string> nameList;
char fileName[50];
cout << "Please Enter file name: ";
cin >> fileName;
ifstream read(fileName);
if(!read){
cout << "File not found!" << endl;
return -1;
}
while(read.good()){
if(!read.eof()){
copy(istream_iterator<string>(read),istream_iterator<string>(),inserter(nameList,nameList.end()));
}
}
read.close();
cout<<endl;
copy(nameList.begin(),nameList.end(),ostream_iterator<string>(cout," "));
cout<<endl;
return 0;
}