14

C ++で aCStringをaに変換するにはどうすればよいですか?double

Unicodeのサポートもいいでしょう。

ありがとう!

4

4 に答える 4

30

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

于 2009-05-27T16:46:36.480 に答える
5

を使用して、何でも何にでも変換できますstd::stringstream。唯一の要件は、演算子>><<が実装されていることです。文字列ストリームは<sstream>ヘッダーファイルにあります。

std::stringstream converter;
converter << myString;
converter >> myDouble;
于 2009-05-30T02:40:14.097 に答える
3

Boost lexical_castライブラリを使用すると、

#include <boost/lexical_cast.hpp>
using namespace boost;

...

double d = lexical_cast<double>(thestring);
于 2009-05-28T04:16:38.447 に答える
1

strtod(またはwcstod)は、文字列を倍精度値に変換します。

<stdlib.h>または<wchar.h>

于 2009-05-27T16:45:14.440 に答える