c++字符串拆分

 1 static void SplitString(const string& data, const string& delim,
 2                   std::vector<string>* result) {
 3   std::string::size_type pos;
 4   const int size = data.size();
 5 
 6   for(int index = 0; index < size; ++index) {
 7     pos = data.find(delim, index);
 8     if (std::string::npos != pos &&
 9         pos < size) {
10       result->emplace_back(data.substr(idx, pos - index));
11       index = pos + delim.size()-1;
12     } else {   // 最后一个element
13       result->emplace_back(data.substr(index));
14     }
15   }19 }

 

posted @ 2023-04-06 19:26  郭流水  阅读(30)  评论(0编辑  收藏  举报