perogram

文字列 分割 C++ split

vector<string> split_str(string s, char c){
    vector<string> ret;
    stringstream ss;
    FOR(i, 0, s.size()){
        if(s[i]==c){
            ret.push_back(ss.str());
            ss.str("");
            ss.clear();
        }else{
            ss << s[i];
        }
    }
    ret.push_back(ss.str());
    return ret;
}

How to use

vector<string> S = split_str("a,b,c", ',');