C ++で aCString
をaに変換するにはどうすればよいですか?double
Unicodeのサポートもいいでしょう。
ありがとう!
C ++で aCString
をaに変換するにはどうすればよいですか?double
Unicodeのサポートもいいでしょう。
ありがとう!
ACString
はに変換できますLPCTSTR
。これは基本的に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);