Reputation: 25048
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
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
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
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