samprat
samprat

Reputation: 2214

std::find failed to compile

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 .

Upvotes: 0

Views: 255

Answers (1)

juanchopanza
juanchopanza

Reputation: 227390

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= ':';

Upvotes: 4

Related Questions