Reputation: 319
Function CommandLineToArgvW
is giving me commandline arguments in LPWSTR
type. I need these arguments in string
.
Would someone please tell me how to convert LPWSTR
to string
?
I'm using mingw.
Upvotes: 24
Views: 56541
Reputation: 31
This is how you can convert LPWSTR to string:
// Assume you have initialized the lpwstr variable
std::wstring wString;
wString.append(&lpwstr[0]);
std::string convertedString(wString.begin(), wString.end());
Easy peasy
Upvotes: 0
Reputation: 62
Let's say yout LPWSTR variable is myVarL:
wstring ws( myVarL );
string myVarS = string( ws.begin(), ws.end() );
should make what you want
Upvotes: 3
Reputation: 6053
std::string MyString = CW2A (L"LPWSTR STRING");
You need to include atlstr.h
for CW2A
Upvotes: 33
Reputation: 14678
Try to use following API functions :
And comparision of both methods WideCharToMultiByte() vs. wcstombs()
Upvotes: 9