Convert LPWSTR to string
44,508
Solution 1
Try to use following API functions :
And comparision of both methods WideCharToMultiByte() vs. wcstombs()
Solution 2
std::string MyString = CW2A (L"LPWSTR STRING");
You need to include atlstr.h
for CW2A
Solution 3
Let's say yout LPWSTR variable is myVarL:
wstring ws( myVarL );
string myVarS = string( ws.begin(), ws.end() );
should make what you want
Related videos on Youtube
Author by
leggo
Updated on November 22, 2020Comments
-
leggo over 3 years
Function
CommandLineToArgvW
is giving me commandline arguments inLPWSTR
type. I need these arguments instring
. Would someone please tell me how to convertLPWSTR
tostring
?
I'm using mingw.-
Chris O almost 12 years
std::wstring someParam = std::wstring(argv[0]);
-
-
Praetorian almost 12 yearsThe
CW2A
macro converts a wide character string to an ASCII string, so why are you sticking the result back into awstring
? -
Erik Aronesty over 11 yearsWhat do you #include for CW2A?
-
Louis Waweru about 10 years@ErikAronesty
atlstr.h
-
M.M over 5 yearsThis will not properly deal with most of the possible characters in a wide string
-
sergiol over 3 yearsThis will not go well for japanese characters.