boost::algorithm::compare & const char
boost::algorithm::compare & const char
用#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
?我没有定义字符串吗?
boost::algorithm::contains
测试一个序列是否包含在另一个序列中,而不测试一个项是否包含在一个序列中。你正在传递一个字符串序列和一个字符序列(又名字符串);因此,当它尝试将字符串与字符进行比较时会出现错误。
相反,如果您想在字符串序列中查找字符串,请使用std::find
:
while (std::find(lexeme.begin(), lexeme.end(),
std::to_string(commandLine.at(position))) == lexeme.end())
{
--position;
}