I'm trying to find the best method to look up a which lines in a large file contain a certain word.
For example if you had the following file:
cat dog monkey
banana chair elephant
monkey phone platypus cat
I'd like it to be able to return 0, 2 for "cat"
I'd expect the function prototype to look something like this:
std::vector<int> FindWords(std::string word);
I'd like to pre-process the file into some data structure, so that lockups can be done quickly giving the line numbers that word is contained on. I'm aware std::map could do this if there was only one instance of the word but there are more.
What is the most appropriate algorithm for this?