困惑如何在C ++中使用strtod()从字符串转换为双精度 [英] Confused how to convert from a string to double using strtod() in C++

查看:38
本文介绍了困惑如何在C ++中使用strtod()从字符串转换为双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人可以解释如何使用该功能,那就太好了.我不明白这些参数.

If someone could explain how to use the function, that would be great. I don't understand the parameters.

谢谢

推荐答案

第一个参数是指向chars的指针.c_str()为您提供了来自字符串对象的指针.第二个参数是可选的.它会包含一个指向字符串中数值之后的下一个char的指针.参见 http://www.cplusplus.com/reference/clibrary/cstdlib/strtod/了解更多信息.

First parameter is a pointer to the chars. c_str() gives you that pointer from a string object. Second parameter is optional. It would contain a pointer to the next char after the numerical value in the string. See http://www.cplusplus.com/reference/clibrary/cstdlib/strtod/ for more infos.

string s;
double d;

d = strtod(s.c_str(), NULL);

这篇关于困惑如何在C ++中使用strtod()从字符串转换为双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆