在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
void AnalyzeStr2Number(vector<int>& v, const string& str, const std::string& separator) { v.clear(); if (str.empty()) return; std::string strTmp; int pos1 = 0; int pos2 = 0; for (; (pos2 = str.find(separator, pos1)) != std::string::npos;) { strTmp = str.substr(pos1, pos2 - pos1); v.push_back(atoi(strTmp.c_str())); pos1 = pos2 + 1; } } int main() { std::string str("11;22;33;44;55;"); std::vector<int> v; AnalyzeStr2Number(v, str, ";"); for (int i=0; i<v.size(); ++i) cout<<v[i]<<endl; return 0; }
|
请发表评论