从字符串中读取多个逗号分隔的双精度数
我需要从字符串中获取一些双打。
string data = getMyData();
char** next;
double start = strtod(data.c_str(), next);
if (&data == &(*next)) //check wether a double has been found - not working
{
std::cerr << "Value can't be read.\nAborting.";
return;
}
我的想法是检查数据的第一个字符和下一个字符的内存地址。 目前我正在自学学习 C++,所以如果能得到最好的解决方案而不仅仅是一个可行的解决方案,那就太好了。
I need to get some doubles from a string.
string data = getMyData();
char** next;
double start = strtod(data.c_str(), next);
if (&data == &(*next)) //check wether a double has been found - not working
{
std::cerr << "Value can't be read.\nAborting.";
return;
}
My idea is to check for memory address of data's first char and next.
At the moment I'm learning C++ in self education so it would be nice to get the best solution and not just a working one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该是:
请记住,如果这些以逗号分隔,则
next
将指向下一个逗号,而不是下一个数字的开头。It should be:
Remember that
next
will point to the next comma if these are comma-separated, not the beginning of the next number.