C++文本去重算法

180it 2020-02-05 PM 2336℃ 0条

include

include

include

include

include

using namespace std;

ifstream & open_file(ifstream &in, const string & file)
{

in.close();
in.clear();
in.open(file.c_str());
return in;

}

int main(int argc,char *argv[])
{

string filename;
filename = argv[1];

cout << "正在文本去重:" << filename << endl;
cout << "请稍后..."; 

set <string> ss;
set <string>::iterator iter;
ifstream infile;
ofstream ofile;


if (!open_file(infile,filename ))
{
    cerr << "没有加载文件!" << endl;
    return 0;
}
string textline;
while (getline(infile, textline))

 if(strstr(textline.c_str(),"    "))
 {
    ss.insert(textline);
}

ofile.open(argv[2]);
for (iter = ss.begin();iter != ss.end();iter++)
    ofile << *iter << endl;
return 0;

}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

C++文本去重算法