Hi im trying to write a program that reads in a text file. The user can search for a specific word and it will output another file. The new file will have the line of the word that appeared.
Ex. "Hi my name is Cody.
I'm learning to code and need help."
If the user searches for name the new output file have
"Hi my name is Cody."
If I got this right, you open a text file, and search for a word, and when you find it you want to output the entire line that the word is in into another file?
If so, you want to use getline when you take the input in from the file. Otherwise, you'll lose your formatting with ">>". You can keep a vector of string that holds the contents of the whole file, or you can search through the file every time using getline. You'll search through the acquired string for the word (which there are many ways to do, string stream comes to mind), and if it's there, you can output the whole line onto the new file.