64,646
社区成员
发帖
与我相关
我的任务
分享
#include<vector>
#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str;
vector<string> vec,svec;;
ifstream ifile("file.txt",ios::in | ios::binary);//打开你的第一个样本文件
if(!ifile)
{
cout<<"cannot open file! "<<endl;
return 1;
}
while(getline(ifile,str))
vec.push_back(str);
ifile.close();
cin.clear();
ifstream ifile1("file1.txt",ios::in | ios::binary);//打开你的第2个要改的文件
if(!ifile1)
{
cout<<"cannot open file! "<<endl;
return 1;
}
while(getline(ifile1,str))
svec.push_back(str);
ifile1.close();
vector<string>::iterator beg=vec.begin();
vector<string>::iterator beg1=svec.begin();
beg=find(vec.begin(),vec.end(),str);
if(beg!=vec.end())
{
while(beg!=vec.end())
*beg1++=*beg++;
}
for(vector<string>::iterator ix=vec.begin();ix!=vec.end();++ix)
cout<<*ix<<endl;//输出交换了的结果
system("pause");
}