C++ Find string of string in list<string>variable name -


in declaration, make list follow

list<string> abc; 

and have saved in it.

and want keyword search.

int counter = 0; list<string>::iterator it; key = "something"  (it = abc.begin(); != abc.end(); it++){     if(*it.find(key) != std::string::npos)         counter++; } 

and gives error "no member named 'find' in std::_1::_list_iterator, void*>'; did mean use -> instead of .?"

so changed if(*it->find(key) != std::string::npos) , gives error "indirection requires pointer operand('size_type'(aka 'unsigned long') invalid)"

do know problem?

also have tried cout type of list "cout << type of (*it)" comes out error...

you want first dereference iterator , then call find:

if(it->find(key) != std::string::npos) 

which equivalent to:

if((*it).find(key) != std::string::npos) 

what wrote first, *it.find(key), parsed compiler *(it.find(key)), i.e. first call find on it , dereference result.

what tried after that, *it->find(key), parsed *(it->find(key)), i.e. first dereference it, call find on result, , dereference result of find.

none of them wanted.

to remember:

  • a->b = (*a).b
  • *a.b = *(a.b)

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -