1 int splitstr(const std::string& str, char tag) 2 { 3 vector<string> vec_str; 4 std::string subStr; 5 for (size_t i = 0; i < str.length(); i++) 6 { 7 if (tag == str[i]) //完成一次切割 8 { 9 if (!subStr.empty()) 10 { 11 vec_str.push_back(subStr); 12 subStr.clear(); 13 } 14 } 15 else //将i位置的字符放入子串 16 { 17 subStr.push_back(str[i]); 18 } 19 } 20 if (!subStr.empty()) //剩余的子串作为最后的子字符串 21 { 22 vec_str.push_back(subStr); 23 } 24 return 1; 25 26 }
标签:分割,函数,push,back,subStr,vec,str,字符串 From: https://www.cnblogs.com/lihongbing1997-1004/p/17090217.html