1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream myfile_in ("test.txt");
ofstream myfile_out ("test1.txt");
string line;
void find_and_replace( string &source, string find, string replace ) {
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;
char mychar [] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
string strcomma ;
string strspace ;
while (! myfile_in.eof() )
{
getline (myfile_in,line);
strcomma = mychar [i] + ",";
strspace = mychar [i] + " ";
find_and_replace( line , strcomma , strspace );
i++;
}
myfile_in.close();
}
else cout << "Unable to open file(s) ";
system("PAUSE");
return EXIT_SUCCESS;
return 0;
}
|