将 char 数组转换为 WCHAR 数组的最简单方法是什么?
在我的代码中,我收到一个 const char array
,如下所示:
const char * myString = someFunction();
现在我想将其作为 wchar array
进行后处理,因为我之后使用的函数不处理窄字符串。
实现这一目标最简单的方法是什么?
最终MultiByteToWideChar? (但是,由于它是我作为输入获得的窄字符串,因此它没有多字节字符=>;可能不是最漂亮的解决方案)
In my code, I receive a const char array
like the following:
const char * myString = someFunction();
Now I want to postprocess it as a wchar array
since the functions I use afterwards don't handle narrow strings.
What is the easiest way to accomplish this goal?
Eventually MultiByteToWideChar? (However, since it is a narrow string which I get as input, it doesn't have multibyte characters => probably not the most beautiful solution)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您在窄字符串中使用扩展字符,否则 MultiByteToWideChar 将起作用。如果它是一个普通的字母数字字符串,那么它应该可以正常工作。
您还可以查看 mbstowcs,它稍微简单一些,但不提供相同数量的控制。
MultiByteToWideChar will work unless you are using extended characters in your narrow string. If its a plain alpha numeric string then it should work fine.
you can also look at mbstowcs which is a little less convoluted but doesn't offer the same amount of control.