@店长大人
正则表达式方法
#include <iostream>
#include <regex>
using namespace std;
vector<string> get_params(string str){
vector<string> result;
regex base_regex("^(.*?):(.*?),(.*?)N,(.*?)E,(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?)$");
smatch base_match;
if (regex_match(str, base_match, base_regex)) {
if (base_match.size()>1)
for (unsigned int i = 1; i < base_match.size(); ++i)
result.push_back(base_match[i]);
}
return result;
}
int main() {
string S = "+CMGLOC:102701.328,3639.6511N,11653.4980E,11.3,-4.4,2,0.00,0.0,0.0,240721,03";
vector<string> result=get_params(S);
for (auto s:result)
cout << s << endl;
return 0;
}