如何将CString转换为C ++中的双引号? [英] How do I convert a CString to a double in C++?

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

问题描述

如何在C ++中将 CString 转换为 double

How do I convert a CString to a double in C++?

Unicode支持也是很好的。

Unicode support would be nice also.

谢谢!

推荐答案

一个 CString 可以转换成一个 LPCTSTR 基本上一个 const char * const wchar_t * 在Unicode构建中)

A CString can convert to an LPCTSTR, which is basically a const char* (const wchar_t* in Unicode builds).

知道这一点,您可以使用 atof( )

Knowing this, you can use atof():

CString thestring("13.37");
double d = atof(thestring).

...或用于Unicode构建, _wtof()

...or for Unicode builds, _wtof():

CString thestring(L"13.37");
double d = _wtof(thestring).

...或支持Unicode和非Unicode构建...

...or to support both Unicode and non-Unicode builds...

CString thestring(_T("13.37"));
double d = _tstof(thestring).

_tstof()是一个宏根据 _UNICODE 是否扩展为 atof() _wtof() code>被定义)

(_tstof() is a macro that expands to either atof() or _wtof() based on whether or not _UNICODE is defined)

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

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