0
votes

My project failed to build if I use std::find in a code . The error I got are the followings

usr/include/c++/4.6/bits/stl_algo.h:162:4: error: no match for ‘operator==’ in ‘_first._gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* with _Iterator = char*, _Container = std::basic_string, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = char& == __val’ /usr/include/c++/4.6/bits/stl_algo.h:162:4: note: candidates are:

Below are my code ..

        std::string lValueCmd = "";
        std::string lModeType = "";
        std::string lAPModeCmd = "sudo iwconfig /sbin/wlan0 | grep -i 'Mode:' | awk '{print $1}'";
      // function to retrive values from linux command and store it in lValueCmd
      lResult =    RequestCmdOutput( lAPModeCmd, lValueCmd )      ; // function to retrive values from linux command and store it in lValue Cmdd

     // std::cout << " the string is " << lValueCmd << std::endl;// debug
      std::string delimiter= ":";

      std::string::iterator pos;
      pos= std::find( lValueCmd.begin(), lValueCmd.end(), delimiter); // no error if I comment this line.

The Header files , I have used are iostream , algorithm and string .

1
If a class has an equivalent method to a generic algorithm, use the class method. It is usually faster. In this case, you'd probably be better off using std::string::find() unless you really need to return an iterator (which is not usually the case working with std::string).Gorpik

1 Answers

4
votes

You need to search for a single character, since "'" is a null terminated string, so consists of characters ' and \0, and your current delimiter is an std::string. std::find will compare elements of the string, which are themselves single characters:

char delimiter= ':';