c++ - Iterating through a vector without begin and end -


i have vector of keywords , need iterate through it.

my attempt :

bool iskeyword(string s) {   return find(keywords, keywords + 10, s ) != keywords + 10; } 

however works array not vector. how can change + 10 iterate through vector? need since can't use end , begin because not have c++11 support.

error given above code:

error: no matching function call 'find(std::vector<std::basic_string<char> >&, std::vector<std::basic_string<char> >::size_type, std::string&)'| 

use begin() , end() this:

find(keywords.begin(), keywords.end(), s ) 

here example:

#include <iostream> #include <vector> #include <string> #include <algorithm>    // std::find  using namespace std;  bool iskeyword(string& s, std::vector<string>& keywords) {   return (find(keywords.begin(), keywords.end(), s ) != keywords.end()); }  int main() {     vector<string> v;     string s = "stackoverflow";     v.push_back(s);     if(iskeyword(s, v))         cout << "found\n";     else         cout << "not found\n";     return 0; } 

as others state, not need c++11 application.

ref, of std::find.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -