Dec 18, 2015 at 3:55pm UTC
hi guys i've written this small piece code ehen i use the find or std::distance function it shows this error "error: no matching function for call to 'find(std::vector<std::basic_string<char> >::iterator, std::vector<std::basic_string<char> >::iterator, std::string&)"
despite declaring all the headers how solve this?
int check_for_command(string input)
{ char *msgs[]={"open google","facebook login","open facebook","open gmail","open twitter",
"open instagram","open youtube","open browser"};
vector<string> v(msgs,msgs+8);
if("open twitter"==find(begin(v),end(v),input))
cout<<"ok";
Dec 18, 2015 at 4:10pm UTC
As your error message states there is no member function named find() in the vector class. Did you forget to include the <algorithm> include file?
Why are you using an array of C-strings? Why not just use a vector of strings in the first place?
1 2
vector<string> vectString{"open google" ,"facebook login" ,"open facebook" ,"open gmail" ,"open twitter" ,
"open instagram" ,"open youtube" ,"open browser" };
Last edited on Dec 18, 2015 at 4:13pm UTC
Dec 18, 2015 at 4:14pm UTC
as u said i've made the changes but still its not resolved i cant use the find neither distance function :(
Dec 18, 2015 at 4:21pm UTC
What exactly are you trying to do in that if statement?
Did you lookup and study the documentation for the std::find() function?
You keep calling about "distance" yet I see nothing in your snippet relating to this term. Do you perhaps mean std::distance?
i've made the changes but still its not resolved
Post your current code.
Last edited on Dec 18, 2015 at 4:22pm UTC