find string in vector

So the program reads contents from a text file into a vector and then the user enters in a string that they want to search for. The program iterates through the vector to find the string and then saves that line to another vector to display later(incase there is more then 1 instance of the string found). Here is what I have atm:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void doSearch(vector<string> &phonelist, string searcher, vector<string> &holdNumbers)
{

	int i = 0;
	string value;

	for (i = 0; i < phonelist.size(); i++)
	{
		if (phonelist.at(i) == searcher)
		{
			value = phonelist.at(i);
			holdNumbers.push_back(value);
		}
	}
	cout << holdNumbers.at(0);
}


I just get an R6010 error -abort() has been called.
Line 15 will cause an exception to be thrown if no matching numbers were found.
Consider something like http://www.cplusplus.com/reference/algorithm/copy_if/

(and then naturally print only if !empty() )
Last edited on
Topic archived. No new replies allowed.