#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string word,word_1,word_2;
fstream iofile("d:\\a.txt",ios_base::in|ios_base::out);
if(!iofile)
{
cerr<<"error:unable to open !"<<endl;
// return -1;
}
cout<<"input a word you want to change"<<endl;
cin>>word_1;
cout<<"input a word you want to change to"<<endl;
cin>>word_2;
while(iofile>>word)
{
if(word==word_1)//替换不成,要用指针吗?
iofile<<word_2;
}
}
#include <string>
#include <fstream>
using namespace std;
int main()
{
string word,word_1,word_2;
fstream iofile("d:\\a.txt",ios_base::in|ios_base::out);
if(!iofile)
{
cerr<<"error:unable to open !"<<endl;
// return -1;
}
cout<<"input a word you want to change"<<endl;
cin>>word_1;
cout<<"input a word you want to change to"<<endl;
cin>>word_2;
while(iofile>>word)
{
if(word==word_1)//替换不成,要用指针吗?
iofile<<word_2;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货