std::find 没有按我的预期进行评估。
我有一个向量 lexeme_ 定义为
static const std::string delimiters_[] = {" ", ",", "(", ")", ";", "=", ".", "*", "-"};
static std::vector<std::string> lexeme_(std::begin(delimiters_), std::end(delimiters_));
我有一个使用std::find
定义为的评估
while ( std::find(lexeme_.begin(),lexeme_.end(),std::string(&commandLine_.at(position_))) == lexeme_.end())
{
// Concat each successive alphanumeric character to 'token'
token += commandLine_.at(position_);
// Update the index into 'commandLine'
position_ += 1;
}
评估应该将char
lexeme_ 中的 achar
与类似于此 Java 表达式的命令行中的 a 进行比较
!lexeme.contains(Character.toString(commandLine.charAt(position)))
评估应该比较char
s 并且如果它确定char
在delimiters
比较中满足 a in ,则 while 循环将退出。
测试用例
#include<algorithm>
#include<iostream>
static const std::string delimiters_[] = {" ", ",", "(", ")", ";", "=", ".", "*", "-"};
static std::vector<std::string> lexeme_(std::begin(delimiters_), std::end(delimiters_));
std::string commandLine = "check me";
while (std::find(lexeme_.begin(),lexeme_.end(),std::string(&commandLine_.at(position_))) == lexeme_.end())
{
std::cout "I should stop printing when encountering a space ' ' << std::endl;
}