0

コードでstd::findを使用すると、プロジェクトのビルドに失敗しました。私が得たエラーは次のとおりです

usr/include/c++/4.6/bits/stl_algo.h:162:4: エラー: '_ firstの 'operator==' に一致しません。_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: 注: 候補は:

以下は私のコードです..

        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.

私が使用したヘッダー ファイルは、iostream、algorithm、および string です。

4

1 に答える 1

4

"'"はヌルで終了する文字列であり、文字'\0で構成され、現在の区切り文字は であるため、単一の文字を検索する必要が ありますstd::stringstd::findそれ自体が単一の文字である文字列の要素を比較します。

char delimiter= ':';
于 2012-12-21T12:52:29.837 に答える