I am trying to search a vector of string names for matches. Names can be more than one word so in prompting the user I am using getline(std::cin, name); however I can never find matches with the existing names in the vector. How do I remove the extra "garbage" from the getline return so it will match with what I have in the vector?
Asked
Active
Viewed 428 times
0
-
what kind of `extra garbage` have you seen? – taocp Mar 31 '13 at 02:23
1 Answers
0
use the delimiter, '\0'.
i.e.:
getline(cin, name, '\0');
and check this out: http://www.cplusplus.com/reference/string/string/getline/
and this: http://www.cplusplus.com/reference/istream/istream/ignore/

Alexandra
- 56
- 1
- 5