字符串分隔
将一个字符串string 通过分隔符存入到一个vector中。
vector<string> split(const string &s, const char *delim) { vector<string> ret; size_t last = 0; auto index = s.find(delim, last); while (index != string::npos) { if (index - last > 0) { ret.push_back(s.substr(last, index - last)); } last = index + strlen(delim); index = s.find(delim, last); } if (!s.size() || s.size() - last > 0) { ret.push_back(s.substr(last)); } return ret; }