指定分割符,分割字符串并存放到 list 中

来源:互联网 发布:java解析excel数据 编辑:程序博客网 时间:2024/06/06 19:02
#include <string>
#include <sstream>
#include <list>
#include <algorithm>

using namespace std;

 //string ProName = "1.exe/2.exe/3.exe"
//拆分为1.exe, 2.exe, 3.exe, 放到 list<string> 里面
void strConvert(const string str, list<string> &strList)
{
    if (str.empty())    return;
    strList.clear();
    replace((char*)str.c_str(), (char*)(str.c_str()+str.length()), '//', ' ');
    stringstream ss(str);
    string tmpStr;
    do
    {
        ss >> tmpStr;
        strList.push_back(tmpStr);
    } while(ss.good());    
}


这里的分割符号为 “/”,使用的时候可以更换成其他符号,比如 “|”
原创粉丝点击