How to do the transform bstr_t to double in c++?
I was thinking to convert to *char, then *char to double?
If you have a char*
or wchar_t*
string, use the strtod
/ wcstod
functions to read a double.
Eg 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.
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
Call wcstod or _wcstod_l if you want to control locale.
bstr_t myBstr_t = L"1.234";
double d = wcstod(myBstr_t, NULL);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.