zoukankan      html  css  js  c++  java
  • C++分割字符串

    "100,100;500,500;300,300;150,150;30,30"

    static void split(const string& src, const string& separator, vector<string>& dest)
        {
            string str = src;
            string substring;
            string::size_type start = 0, index;
    
            do
            {
                index = str.find_first_of(separator,start);
                if (index != string::npos)
                {    
                    substring = str.substr(start,index-start);
                    dest.push_back(substring);
                    start = str.find_first_not_of(separator,index);
                    if (start == string::npos) return;
                }
            }while(index != string::npos);
    
            //the last token
            substring = str.substr(start);
            dest.push_back(substring);
        }
    //调用
    vector<string> vecData;
                CXCommon::split(CCXmlReader::getXMLNodeAttribStrs(pItemNode, "data"), string(";"), vecData);
                for (unsigned int i = 0; i < vecData.size(); i++)
                {
                    vector<string> vecPos;
                    CXCommon::split(vecData[i], string(","), vecPos);
                    if (!vecPos.empty())
                    {
                        mapInfo.foundationPos.push_back(CCPoint(atof(vecPos[0].c_str()), atof(vecPos[1].c_str())));
                    }
                }
  • 相关阅读:
    作业作业
    Alpha 冲刺 (4/10)
    Alpha 冲刺 (3/10)
    Alpha 冲刺 (2/10)
    Alpha 冲刺 (1/10)
    项目需求分析评审表
    项目需求分析答辩总结
    项目选题报告答辩总结
    UML
    各组项目答辩评分与存在问题
  • 原文地址:https://www.cnblogs.com/newlist/p/3142206.html
Copyright © 2011-2022 走看看