what i found:
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream myfile_in ("Lista1.txt");
ofstream myfile_out ("Lista2.txt");// problem1
string line;
void find_and_replace( string &source, string find, string replace ) { // problem2
size_t j;
for ( ; (j = source.find( find )) != string::npos ; ) {
source.replace( j, find.length(), replace );
}
myfile_out << source <<endl;
cout << source << endl;
}
int main () {
if (myfile_in.is_open())
{
int i = 0;
string strcomma ;
string strspace ;
while (! myfile_in.eof() )
{
getline (myfile_in,line);
strcomma = "john";
strspace = "mariah";
find_and_replace( line , strcomma , strspace );
i++;
}
myfile_in.close();
}
else cout << "Unable to open file(s) ";
system("PAUSE");
return 0;
}
i have 2 problem "yet"
1) the file doesn't overwrite
2)this code MUST be a method, when i try to put inside edit(){...} i have a problem with the method 'void find_and_replace'