在 C++ 中解析坐标字符串的最佳方法

apa*_*ual 1 c++ parsing coordinates

我想知道哪种方法是解析stringC++ 中相同坐标的最佳方法。

例子:

1,5
42.324234,-2.656264
Run Code Online (Sandbox Code Playgroud)

结果应该是两个double变量...

sta*_*ust 5

如果字符串的格式总是像x,y,那么这应该就足够了。

#include <string>
#include <sstream>

double x, y;
char sep;
string str = "42.324234,-2.656264";
istringstream iss(str);

iss >> x;
iss >> sep;
iss >> y;
Run Code Online (Sandbox Code Playgroud)