どのように私はC ++で二重にCStringの変換のですか?
-
06-09-2019 - |
質問
私はC ++でCString
にdouble
を変換する方法を教えてください。
Unicodeサポートもいいだろう。
ありがとうございます。
解決
CString
は、基本的に(ユニコードでLPCTSTR
ビルド)const char*
ある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
のいずれかに展開されるマクロである)
他のヒント
あなたはのものには何ものstd::stringstream
を使用して変換することができます。唯一の要件は、事業者の>>
と<<
が実装されることです。 Stringstreamsは<sstream>
ヘッダファイルで見つけることができます。
std::stringstream converter;
converter << myString;
converter >> myDouble;
ライブラリのlexical_castブーストと、あなたが
#include <boost/lexical_cast.hpp>
using namespace boost;
...
double d = lexical_cast<double>(thestring);
所属していません StackOverflow