C++ 切割string splite方法的实现

vector splitStr(string str, char delimiter){
        vector r;
        string tmpstr;
        while (!str.empty()){
            int ind = str.find_first_of(delimiter);
            if (ind == -1){
                r.push_back(str);
                str.clear();
            }
            else{
                r.push_back(str.substr(0, ind));
                str = str.substr(ind + 1, str.size() - ind - 1);
            }
        }
        return r;
    }

你可能感兴趣的:(LeetCode算法小技巧)