#include<fstream>
#include<iterator>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
string from,to;
cin>>from>>to;
ifstream ifs(from.c_str());
istream_iterator<string>ii(ifs);
istream_iterator<string>eos;
vector<string>v;
copy(ii,eos,back_inserter(v));
sort(v.begin(),v.end());
copy(v.begin(), v.end(),ostream_iterator<string>(cout, " ") );
ofstream ofs(to.c_str(),ios_base::app);
ostream_iterator<string>oo(ofs);
unique_copy(v.begin(),v.end(),*oo);
ifs.close();
ofs.close();
system("pause");
return 0;
}
文件读写与排序
本文介绍了一个使用C++实现的程序,该程序从一个文本文件中读取字符串,并将其排序后输出到另一个文件及控制台。涉及的技术包括使用标准模板库(STL)中的容器进行数据操作、文件输入输出以及迭代器的使用。
1208





