STL

I am a bit stuck on this question for my assignment

int find_first(list<string>& data, string query)
{
...
}

Implement the above function. It should find the first occurrence of the query string within the list,and return the index (i.e. how far into the list before it was found).

I am not sure how to go about doing this.
I think I have figured out how to do this now I have to adapt it so it must now find all
occurrences. All corresponding indices should be returned as a list.

I am a little stuck. I think you have to create a new list, each time you find the string find the corresponding indices and add it to the new list then return the new list. I am not sure how to do it though.
Last edited on
yes, you need to return a container (any type) of all the indices.

its the same code, except you no longer stop looking after finding it once, you go again until end of the input list is reached, adding each hit, return empty list if none at all.
Last edited on
Topic archived. No new replies allowed.