C++ 中split函数的实现

C++中string没有自带的split()函数,需要自己实现

void split(const string& s, vector<int>& sv, const char flag = ' ') {
    sv.clear();
    istringstream iss(s);
    string temp;

    while (getline(iss, temp, flag)) {
        sv.push_back(stoi(temp));
    }
    return;
}

使用了stringstream,需要在头文件包含 #include <sstream>

 

 

 

转载自其他博客

posted @ 2020-06-10 23:14  sbj123456789  阅读(1178)  评论(0编辑  收藏  举报