c++ - std::find 编译失败

标签 c++ stl stdstring

如果我在代码中使用 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。

最佳答案

您需要搜索单个字符,因为 "'" 是一个空终止字符串,所以由字符 '\0,并且您当前的分隔符是 std::stringstd::find 将比较字符串的元素,它们本身是单个字符:

char delimiter= ':';

关于c++ - std::find 编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13990561/

相关文章:

c++修改函数内部的char

c++ - 在 Mac OS X 上获取光标位置

c++ - 在传递的对象将要被销毁之前,发出传递 QObject 指针作为参数的信号是否安全?

c++ - 在将 char 数组复制到字符串期间节省 CPU 周期(提高性能)

c++ - 在单个分配中分配一个包含字符串的结构

C++ 排序 - 普通字母后的特殊字符

c++ - 在什么情况下您应该更喜欢使用 std::copy 写入 cout?

C++:如何有效地将值分配给 vector 列表?

c++ - CString::Mid() 是否有等效的 std::string?

c++ - boost::interprocess::basic_string 作为 std::string