如果我在代碼中使用std :: find,我的項目無法生成。我得到的錯誤如下:std :: find無法編譯
usr/include/C++/4.6/bits/stl_algo.h:162:4:錯誤:首先在'_ '中不匹配'operator =='。 _gnu_cxx :: __ normal_iterator < _Iterator,_container> ::運算符*與_Iterator =字符*,_container =性病:: basic_string的,__gnu_cxx :: __ normal_iterator < _Iterator,_container> ::參考=炭& == __val」 的/ usr /包括/ C++/4.6 /比特/ 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的,算法和字符串。
如果類具有一個通用的算法等效的方法,使用類方法。它通常更快。在這種情況下,除非你確實需要返回一個迭代器(通常不會使用'std :: string'),否則你最好使用'std :: string :: find()'。 – Gorpik