Parse (split) a string in C++ using string delimiter (standard C++)

后端 未结 20 2111
时光说笑
时光说笑 2020-11-21 23:44

I am parsing a string in C++ using the following:

using namespace std;

string parsed,input=\"text to be parsed\";
stringstream input_stringstream(input);

i         


        
20条回答
  •  甜味超标
    2020-11-21 23:52

    std::vector split(const std::string& s, char c) {
      std::vector v;
      unsigned int ii = 0;
      unsigned int j = s.find(c);
      while (j < s.length()) {
        v.push_back(s.substr(i, j - i));
        i = ++j;
        j = s.find(c, j);
        if (j >= s.length()) {
          v.push_back(s.substr(i, s,length()));
          break;
        }
      }
      return v;
    }
    

提交回复
热议问题