I am trying to make a function which gets two parameters one Line_number and 2nd a string. This function will open a File Pre-Populated and skip till Line "Line_number" is reached , get that line and post some other line instead.But it does not work. I have seen other solutions but cant find right solution. Kindly help me with it.
fstream Inoutput_file;
void BackPatch(int GotoLineNo, string LineNo)
{
for (int i = 1; i <= GotoLineNo; i++)
{
char* str = new char[20];
Inoutput_file.getline(str, 20, '\n');
if (i == LineNo-1)
{
Inoutput_file.seekp(Inoutput_file.tellg());
Inoutput_file.getline(str, 20, '\n');
cout << str << endl; //prints the correct line
Inoutput_file << "Goto " + str <<endl; //donot work
cout << "Goto " + str<<endl; // Prints correct line
}
}
Inoutput_file.seekp(0);
Inoutput_file.seekg(0);
}
In main:
Inoutput_file.open("example.txt");
BackPatch(3,"Print this to Line 3 instead");
Inoutput_file.close();
I would Also Like to Mention here that I have opened same File with different instance of "ifstream" to work for rest of my program.