如何在C ++中将char *类型转换为double [英] how to convert char* type to double in C++

查看:663
本文介绍了如何在C ++中将char *类型转换为double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char * ptr =0.3312015;



我想得到0.3312015并转换为双重类型,

* ptr只能得到第一个字母0,

怎么写这个程序?

感谢您的回答。

char *ptr = "0.3312015";

I want to get "0.3312015" and convert to double type,
*ptr can only get the first char 0,
how to write this program?
thanks for answer.

推荐答案

使用 atof [ ^ ]功能:就是它的用途!
Use the atof[^] function: that is what it is there for!


使用 std :: istringstream std :: istrstream (如果你可以应对自1998年以来一直悬在后者上的弃用斧头)。您可以从cin中以相同的方式读取该数组中的内容。
Use a std::istringstream or std::istrstream (if you can cope with the axe of deprecation that's been hanging over the latter since 1998). You can read stuff in from that array the same way you can from cin.


这篇关于如何在C ++中将char *类型转换为double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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