如何在C++中将CString
转换为double
?
Unicode支持也很好。
谢谢!
最佳答案
CString
可以转换为LPCTSTR
,它基本上是const char*
(Unicode构建中的const wchar_t*
)。
知道这一点,您可以使用 atof()
:
CString thestring("13.37");
double d = atof(thestring).
...或者对于Unicode构建,
_wtof()
:CString thestring(L"13.37");
double d = _wtof(thestring).
...或同时支持Unicode和非Unicode构建...
CString thestring(_T("13.37"));
double d = _tstof(thestring).
(
_tstof()
是一个宏,它根据是否定义了atof()
扩展为_wtof()
或_UNICODE
)