|If it's plain text and the file is fairly small, it *might* be easier to create an array of strings and read the file into the array, Prompt for your string to insert and then search your array for the word to insert after. Lastly, write out the first part of the array, the word to insert, and then the rest of the array.|
Use the fstream object... when you read the file, it will set the end of file bit, so you'll need to reset it before you can rewrite its contents.
fileobj.open("some file name", ios::in | ios::out);
// read and output the file; request words
// write beginning of array, word, end of array
Now if the file is large, it's *probably* better to create a temp file and two file stream objects - ifstream (read existing) and ofstream (write temp).
It's pretty much the same as before... read the input file, rewind its stream, ask for the word to insert and where, and then as you re-read the input file, output its data to the temp file instead of the screen up until the selected word is reached, then the word, the rest of the input file.
Lastly, you can use two standard C functions remove() and rename() to delete the input file and rename the temp to that of the input file. Both require <cstdio> or stdio.h and take C style strings as file names, so if you're using the string class, remember to use string_obj.c_str()
Obviously, if your input file has multiple occurances of the selected word, you'll have to account for that; similarly, if case is an issue, then you can use isupper/islower or similar.