C++ vector Search value via find()
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main()//from ww w. j a v a 2 s . c o m { vector<string> Words; Words.push_back("Blue"); Words.push_back("Green"); Words.push_back("Teal"); Words.push_back("Brick"); Words.push_back("Purple"); Words.push_back("Brown"); Words.push_back("LightGray"); vector<string>::iterator Result = find(Words.begin(), Words.end(), "LightGray"); if (Result != Words.end()) cout << *Result << endl; else cout << "Value not found!" << endl; Result = find(Words.begin(), Words.end(), "Black"); if (Result != Words.end()) cout << *Result << endl; else cout << "Value not found!" << endl; }