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>

 

 

 

转载自其他博客


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM