使用#include <boost/algorithm/string.hpp>比较std::string和std::vector<std::string>
std::string commandLine
std::string::size_type position
std::string delimiters[] = {" ", ",", "(", ")", ";", "=", ".", "*", "-"};
std::vector<std::string> lexeme(std::begin(delimiters), std::end(delimiters));比较
while (!boost::algorithm::contains(lexeme, std::to_string(commandLine.at(position)))){
position--;
}生成以下错误
Error 1 error C2679: binary '==' : no operator found which takes a right-hand operand of type 'const char' (or there is no acceptable conversion)const char?我不是在定义字符串吗?
发布于 2013-04-09 02:54:27
boost::algorithm::contains测试一个序列是否包含在另一个序列中,而不是测试序列中是否包含一个项目。您传递的是一个字符串序列和一个字符序列(也就是一个字符串);因此,当它尝试将一个字符串与一个字符进行比较时,会出现错误。
相反,如果要在字符串序列中查找字符串,请使用std::find
while (std::find(lexeme.begin(), lexeme.end(),
std::to_string(commandLine.at(position))) == lexeme.end())
{
--position;
}https://stackoverflow.com/questions/15886488
复制相似问题