Consider i have following file ("testt.txt")
abc
123
def
456
ghi
789
jkl
114
Now if i wanted to update the figure next to name ghi (i.e. 789),
how would i do it?
The following code helps me reach there quickly no doubt, but how to update it quickly?
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main() 
{
    int counter = 0;
    string my_string;
    int change = 000;
    ifstream file ( "testt.txt" );
    while(!file.eof())
    {
        counter = counter + 1;
        getline(file, my_string, '\n');
        if (my_string == "ghi") 
        {
            ofstream ofile ( "testt.txt" );
            for (int i = 0; i < counter + 1; i++)
            {
                //reached line required i.e. 789
                //how to process here?
            }
            ofile.close();
            break;
        }
    }
    cout << counter << endl;
    file.close();
    return 0;
}
Clearly the counter here is 5 corresponding to "ghi",
so counter + 1 would point to value 789. How to change it to 000?
------------SOLVED-----------FINAL CODE------
 #include<iostream>
 #include<fstream>
 #include<string>
 #include <cstdio>
using namespace std;
int main() 
{
string x;
ifstream file ( "testt.txt" );
ofstream ofile ( "test2.txt" );
while (!file.eof())
{
    getline(file,x);
    if (x == "789")
    {
        ofile << "000" << endl;
    }
    else
        ofile << x << endl;
}
file.close();
ofile.close();
remove("testt.txt");
return 0;
}
Output ("test2.txt")
abc
123
def
456
ghi
000
jkl
114
 
     
     
    