#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
string sensor_info = "1504491530:51.10";
vector<std::string> v;
string c = ":";
string::size_type pos1, pos2;
pos2 = sensor_info.find(c);
pos1 = 0;
while(std::string::npos != pos2) {
v.push_back(sensor_info.substr(pos1, pos2-pos1));
pos1 = pos2 + c.size();
pos2 = sensor_info.find(c, pos1);
}
if(pos1 != sensor_info.length())
v.push_back(sensor_info.substr(pos1));
cout<<v[0]<<endl;
cout<<v[1]<<endl;
}
初学C++之字符串的拆分
最新推荐文章于 2024-07-25 18:17:30 发布