C++ 将 LPWSTR 转换为字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12460712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert LPWSTR to string
提问by leggo
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.
函数CommandLineToArgvW
给了我命令行参数的LPWSTR
类型。我需要在string
. 有人能告诉我如何转换LPWSTR
为string
吗?
我正在使用 mingw。
采纳答案by rkosegi
Try to use following API functions :
尝试使用以下 API 函数:
And comparision of both methods WideCharToMultiByte() vs. wcstombs()
以及两种方法的比较WideCharToMultiByte() 与 wcstombs()
回答by Chris Dargis
回答by Lambert Duran
Let's say yout LPWSTR variable is myVarL:
假设您的 LPWSTR 变量是 myVarL:
wstring ws( myVarL );
string myVarS = string( ws.begin(), ws.end() );
should make what you want
应该做你想要的