我有以下形式a = x + y或abc = xyz + 5或6 + 5或的字符串
f(p)
我需要的是标记字符串,以便我读取每个字符串operator,operand
因此对于a = x + y令牌返回应该是,a,=,x,+,y并且如果abc=xyz+5它应该返回abc,=,xyz,+,5.请注意,operator和之间可能有空格,也可能没有空格operands
这是我试过的
void tokenize(std::vector<std::string>& tokens, const char* input, const char* delimiters) {
const char* s = input;
const char* e = s;
while (*e != 0) {
e = s;
while (*e != 0 && strchr(delimiters, *e) == 0) {
++e;
}
if …Run Code Online (Sandbox Code Playgroud)