Hi,
im doing this question:
Replace all the occurrences of a string in a file and report number of replacements.
I did the first part of the question, but im having problems with the second part, i which i have to report the number of replacements.
this is the code that i did so far:
Thanks..... all help on how i can solve the second part of the question will be very much appreaciated.
im doing this question:
Replace all the occurrences of a string in a file and report number of replacements.
I did the first part of the question, but im having problems with the second part, i which i have to report the number of replacements.
this is the code that i did so far:
Code:
#include <iostream>
#include <conio.h>
#include <fstream>
using namespace std;
int main()
{
string whole_file, str;
ifstream in ("file.txt");
while (!in.eof())
{
std::getline(in,str,'\n');
whole_file = whole_file + str + "\n";
}
int pos = 0;
while (pos!=-1 && pos<whole_file.length())
{
pos = whole_file.find ("money", 0);
if (pos!=-1)
{
cout<<whole_file.replace(pos, 5, "university", 10);
}
}
cout<<whole_file;
getch();
return 0;
}
Thanks..... all help on how i can solve the second part of the question will be very much appreaciated.
Comment