📜  在 C++ 代码示例中实现拆分功能

📅  最后修改于: 2022-03-11 14:44:50.327000             🧑  作者: Mango

代码示例1
// splits a std::string into vector at a delimiter
vector split(string x, char delim = ' ')
{
    x += delim; //includes a delimiter at the end so last word is also read
    vector splitted;
    string temp = "";
    for (int i = 0; i < x.length(); i++)
    {
        if (x[i] == delim)
        {
            splitted.push_back(temp); //store words in "splitted" vector
            temp = "";
            i++;
        }
        temp += x[i];
    }
    return splitted;
}