字符串分割

std::vector<std::string> split_string(const std::string& str, const std::string& delim) {
  std::vector<std::string> res;
  std::string tmp;
  for (int i = 0; i < str.size(); i++) {
    if (delim.find(str[i]) == std::string::npos) {
      tmp.push_back(str[i]);
    } else {
      res.push_back(tmp);
      tmp.clear();
    }
  }
  res.push_back(tmp);

  return res;
}

全部评论
灵均coding
点赞 回复 分享
发布于 2023-08-19 14:28 北京

相关推荐

不愿透露姓名的神秘牛友
2025-12-19 16:50
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务