I have an input file which contains 3 sentences:
Jane likes chicken.
Alex likes chicken too.
both like chicken.
At the beginning of the 3rd sentence I want to add a word "They" while the reference line is the 1st line i.e "Jane likes chicken".
The code I have tried to develop can do so if reference is made to the exact line where I want to add the word but this is not what I want. Below is the program that I have developed but as I said before, it adds the word when reference is made to the exact line of insertion.
Is there a way whereby I can do something like this:
using namespace std;
/*opens the input file*/
/*this part opens the temperate output file*/
ofstream outfile ("testing_out.txt");
/*this reads the lines in the input file and inserts
a word "They" in one of the lines specified*/
if(line.substr(0,line.find(" "))== "both")
(1) Find a line that begins with "Jane".
(2) Then two (2) line after that line with Jane (which brings me to the line "both like chicken" in this particular case, insert the word "They".
Thanks for your help.