C++ split,字符串分割

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33048069/article/details/79421063
#include <string>
#include <vector>


void SplitStr(std::vector<std::string>&ret,const std::string& src_str,std::string demi)
{
    if (src_str.empty() || demi.empty())return;


    unsigned int iStartPos =0;
    int iPos =0;
    while (iPos != std::string::npos)
    {
        iPos = src_str.find_first_of(demi,iStartPos);
        if(iPos == iStartPos)
        {


        }else
        {
            ret.push_back(src_str.substr(iStartPos,iPos-iStartPos));
        }


        iStartPos=iPos+1;
        iStartPos = src_str.find_first_not_of(demi, iStartPos);
    }
}


int main()
{
   std::vector<std::string>vec;
   std::string str ="123:123123|:456:789:456:?789";
   SplitStr(vec,str,":|?");
   int xx =0;
}

猜你喜欢

转载自blog.csdn.net/qq_33048069/article/details/79421063