i want to replace a certain text in text file and i can't figure it out the code that need to perform this function.
example in my text file have
12345 hello
789 morning
1234 good
text i want to edit
morning
text to replace
night
result :
12345 hello
789 night
1234 good
this is my code
string temp;
ifstream seek1;
ofstream seek2;
seek1.open( "staff_info.txt");
seek2.open( "staff_info.txt", fstream::in | fstream::out | fstream::ate | ios::app);
cout<<"Enter the text that you want to edit\n";
getline(cin, st_txt1);
cout<<"Enter the text to replace\n";
getline(cin, st_txt2);
while (getline(seek1, temp))
{
if (temp.find(st_txt1)!=string::npos)
{
temp.replace(temp.find(st_txt1),st_txt1.length(),st_txt2);
seek2 << temp;
}
}