C++ find()
Search value in vector
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main()//from w ww .ja v a 2s.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; }