What would be the best way to search for a key word in multiple files? I am having trouble figure out the best structure to use, how to separate one word at a time from a file and iterate one file after another.
At a minimum, you are going to need code to get a list of files to search.
Then, you'll need a loop to open each file:
You are going to need code to open each file in your list.
You'll need code to read the file and compare each "word" to the key word.
You didn't specify if you are going to handle file patterns the user might specify, like all files that end in .c, etc. Also, you probably want to open the files in text mode (as opposed to binary.) There can be a lot to this, but I hope this helps you get the creative juices flowing!
I can open the files just fine, however, I have 50 .text files and the exact names of each. I am confused how to loop through them. Can they be stored into an array?
You could use a vector<string> to store the filenames, and then just iterate through it. A nice way to populate the vector could be to use the command prompt arguments.
This what I have now. It will open a file and output what is in it but then I added the for loop to iterate through sequential files: file01, file02, file03.... so why doesn't it work they way I have it?