相关疑难解决方法(0)

C++中的字符串标记化,包括分隔符字符

我有以下形式a = x + yabc = xyz + 56 + 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)

c++ stl

4
推荐指数
1
解决办法
4011
查看次数

标签 统计

c++ ×1

stl ×1