std :: find가 예상대로 평가되지 않습니다.std :: find가 예상대로 작동하지 않습니다.
은 내가 유사한 명령 줄에서 char
에 lexeme_에 char
을 비교하도록되어
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;
}
평가로 정의 std::find
를 사용하여 평가를
static const std::string delimiters_[] = {" ", ",", "(", ")", ";", "=", ".", "*", "-"};
static std::vector<std::string> lexeme_(std::begin(delimiters_), std::end(delimiters_));
는 벡터 lexeme_가 정의한 이 Java 표현
!lexeme.contains(Character.toString(commandLine.charAt(position)))
평가 결과가 char
과 비교되며, 에있는 char
이 만족 스럽다고 판단되면 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;
}
당신이 완전한 테스트 케이스를 만들 수 있습니다 이것을 설명하기? –
@DrewDormann은 인용이 필요합니다. 말했듯이 그것은 우스꽝 스럽다. 확실히 "확실히"빠르지는 않습니다. – sehe
그래서 문제가 무엇입니까? 이 코드는 무엇을하고 무엇을 기대합니까? 그리고 그것이하는 일과 기대 한 것과는 어떻게 다릅니 까? 간단히 말해서, http://whathaveyoutried.com/ – jalf