Search code examples
c++stringstdstringwchar-t

How do I convert wchar_t* to std::string?


I changed my class to use std::string (based on the answer I got here but a function I have returns wchar_t *. How do I convert it to std::string?

I tried this:

std::string test = args.OptionArg();

but it says error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'std::basic_string<_Elem,_Traits,_Ax>'


Solution

  • You could just use wstring and keep everything in Unicode