65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main()
{
ofstream outFile("b.txt",ios::out);
ifstream inFile("haha.txt", ios::in);
if (!(inFile && outFile))
{
cerr << "File could not be opened!" << endl;
exit(1);
}
string str;
while (getline(inFile, str))
{
string s1("我 是 中国人"); //修改后的字符
string s2("中国");//查找的对象
str.replace(str.find(s2,0),s2.length(),s1);
//要修改的话,在这里对str进行处理
outFile << str <<"\n";
}
return 0;
}
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main()
{
ofstream outFile("b.txt",ios::out);
ifstream inFile("haha.txt", ios::in);
if (!(inFile && outFile))
{
cerr << "File could not be opened!" << endl;
exit(1);
}
string str;
while (getline(inFile, str))
{ //要修改的话,在这里对str进行处理
outFile << str <<"\n";
}
return 0;
}