gpt4 book ai didi

c++ - 从字符串中读取多个逗号分隔的 double

转载 作者:行者123 更新时间:2023-11-30 03:03:27 28 4
gpt4 key购买 nike

我需要从字符串中获取一些 double 。

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++,因此最好能获得最佳解决方案,而不仅仅是一个可行的解决方案。

最佳答案

应该是:

char* next;
double start = strtod(data.c_str(), &next);

if (data.c_str() == next)

请记住,next 将指向下一个 逗号(如果它们以逗号分隔),而不是下一个数字的开头。

关于c++ - 从字符串中读取多个逗号分隔的 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9349617/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com