[英]Best way to detect the window coordinates of a drawn line in c++ Builder
[英]Best way to parse coordinates string in C++
我想知道哪種方法是解析C ++中同一string
中的坐標的最佳方法。
例子:
1,5
42.324234,-2.656264
結果應該是兩個double
變量...
如果字符串的格式始終像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;
使用while (std::getline(stream, line))
提取每一行,然后使用line
初始化一個std::istringstream
。 然后,您可以像這樣從中提取:
double x, y;
if (line_stream >> x &&
line_stream.get() == ',' &&
line_stream >> y) {
// Extracted successfully
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.