Monday, December 5, 2016

split

void split(const string &s, char delim, vector<string> &elems) {
    //-------------------------------------------------------
    // This function splits a line into a vector of strings
    // based on a separating character, such as a comma.
    // s is the input string
    // delim is the separating character.
    // elems is the vector that will hold the output.
    //-------------------------------------------------------
    stringstream ss;
    ss.str(s);
    string item;
    elems.clear();
    while (getline(ss, item, delim)) {
        elems.push_back(item); }

}

No comments:

Post a Comment