如何在 C++ 中将 a 转换CString为 a ?double
Unicode 支持也会很好。
谢谢!
ACString可以转换为 a LPCTSTR,这基本上是 a const char*(const wchar_t*在 Unicode 版本中)。
知道了这一点,您可以使用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
您可以使用std::stringstream. 唯一的要求是运营商>>和<<被执行。字符串流可以在<sstream>头文件中找到。
std::stringstream converter;
converter << myString;
converter >> myDouble;
使用 boost lexical_cast 库,你可以
#include <boost/lexical_cast.hpp>
using namespace boost;
...
double d = lexical_cast<double>(thestring);