zoukankan      html  css  js  c++  java
  • C++ 字符串分割,分割到vector中

    #include <string>
    #include <vector>
    using std::string;
    using std::vector;
    
    
    int splitStringToVect(const string & srcStr, vector<string> & destVect, const string & strFlag);
    
    
    int main()
    {
        string str = "asdasdas 
    , sadasd
    , ssdddsrr
     
     
     ss
    ";
        vector<string>   destVect;
        splitStringToVect(str, destVect, "
    ");     //以"
    "为标记,分割字符串到vector中
        return 1;
    }
    
    
    int splitStringToVect(const string & srcStr, vector<string> & destVect, const string & strFlag)
    {
        int pos = srcStr.find(strFlag, 0);
        int startPos = 0;
        int splitN = pos;
        string lineText(strFlag);
    
        while (pos > -1)
        {
            lineText = srcStr.substr(startPos, splitN);
            startPos = pos + 1;
            pos = srcStr.find(strFlag, pos + 1);
            splitN = pos - startPos;
            destVect.push_back(lineText);
        }
    
        lineText = srcStr.substr(startPos, srcStr.length() - startPos);
        destVect.push_back(lineText); 
    
        return destVect.size();
    }


  • 相关阅读:
    格式布局
    tp框架之文件上传
    tp框架之验证码
    tp框架之自动验证表单
    tp框架之留言板练习
    tp框架之session
    tp框架之登录验证
    tp框架之函数调用
    tp框架之分页与第三方类的应用
    tp框架之AJAX
  • 原文地址:https://www.cnblogs.com/yuzhould/p/4454259.html
Copyright © 2011-2022 走看看