edgarmtze
edgarmtze

Reputation: 25048

Converting bstr_t to double

How to do the transform bstr_t to double in c++?

I was thinking to convert to *char, then *char to double?

Upvotes: 1

Views: 2743

Answers (3)

Frank Boyne
Frank Boyne

Reputation: 4570

Call wcstod or _wcstod_l if you want to control locale.

bstr_t myBstr_t = L"1.234";

double d = wcstod(myBstr_t, NULL);

Upvotes: 2

Kerrek SB
Kerrek SB

Reputation: 477140

If you have a char* or wchar_t* string, use the strtod/wcstod functions to read a double.

E.g. using @Steve's suggestion:

_bstr_t x;
double q = wcstod(x, NULL); // implicit conversion!
double p = strtod(x, NULL); // same

Apparently _bstr_t has implicit conversion operators both to const char * and const wchar_t*, so you can use them directly in the float parsing functions.

Upvotes: 4

Steve Townsend
Steve Townsend

Reputation: 54168

You can cast to const char* (there is a converter for this that handles mapping from wide char to MBCS under the covers) and then convert to double as you wish - stringstream::operator>> for example

Upvotes: 2

Related Questions