I would like to convert wstring to wchar_t*. I have tried everything what i know, please help. I would like to convert wstring to wchar_t*.
Did you try reading the reference
const wchar_t* wcs = s.c_str();
There is no way to convert wstring
to wchar_t*
but you can convert it to const wchar_t*
which is what answer by K.Kirsz says.
This is by design because you can access a const pointer but you shouldn't manipulate the pointer. See a related question and its answers.
The best bet is to create a new string using _wcsdup and access the non const buffer, an ascii example is given there.
For unicode:
wstring str = L"I am a unicode string";
wchar_t* ptr = _wcsdup(str.c_str());
// use ptr here....
free(ptr); // free memory when done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With