且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将CString转换为C ++中的双引号?

更新时间:2022-12-12 09:09:55

一个 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)