After getting a struct from C# to C++ using C++/CLI:
public value struct SampleObject
{
LPWSTR a;
};
I want to print its instance:
printf(sampleObject->a);
but I got this error:
Error 1 error C2664: ‘printf’ : cannot convert parameter 1 from
‘LPWSTR’ to ‘const char *’
How can I convert from LPWSTR to char*?
Thanks in advance.
Don’t convert.
Use
wprintfinstead ofprintf:See the examples which explains how to use it.
Alternatively, you can use
std::wcoutas:Similarly, use functions which are designed for wide-char, and forget the idea of converting
wchar_ttochar, as it may loss data.Have a look at the functions which deal with wide-char here: