سؤال

Possible Duplicate:
How to find an item in a std::vector?

Hey like the title suggests i would like to check to see if the vector contains the string "Key". I have been looking around on Google and i cant find anything in the vector library. Can anybody help me with this. Thanks in advance.

هل كانت مفيدة؟

المحلول

You can use std::find for that. Assuming you have an std::vector full of std::strings:

#include <algorithm> // for std::find

std::vector<std::string> v = ....;
std::vector<std::string>::const_iterator it = std::find(v.begin(), v.end(), "Key");
bool found = it != v.end();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top