我有一些像这样的输入:(50.1003781N, 14.3925125E)
它存储在const string & input
. 我要做的是提取括号,获取代表 GPS 协调的数字 - 50.1003781,保存 N 并对第二个坐标执行相同的操作。
所以这是我的代码:
istringstream iStream(input);
char brackets[2]; //To store the brackets
char types[2]; //To store if it is N/S or W/E
char delim; //To store ","
double degrees[2];
iStream >> brackets[0] >> degrees[0] >> types[0] >> delim;
//The delim loads the "," and here goes my problem with whitespace which is next
iStream >> degrees[1] >> types[1] >> brackets[1];
但它在加载时失败degrees[1]
,它加载为零并tellg()
说 -1 可能是因为逗号后有空格。解析后的字符串应该是这样的:
cout << brackets[0]; // "("
cout << degrees[0]; // "50.1003781"
cout << types[0]; // "N"
cout << delim; // ","
cout << degrees[1]; // "14.3925125"
cout << types[1]; // "E"
cout << brackets[1]; // ")"
我试过 skipws 和 noskipws 但没有效果。有人可以帮忙吗?非常感谢。