在 iOS 上将 wchar_t* 转换为 char*
我正在尝试将 wchar_t* 转换为 char*。这是我的代码:
size_t result = wcstombs(returned, str, length + 1);
if (result == (size_t)-1) {
int error = errno;
}
它确实失败了,错误填充为 92 (ENOPROTOOPT) - 协议不可用。
我什至尝试过设置区域设置:
setlocale(LC_ALL, "C");
还有这个:
setlocale(LC_ALL, "");
我很想用静态转换来抛出角色!
I'm attempting to convert a wchar_t* to a char*. Here's my code:
size_t result = wcstombs(returned, str, length + 1);
if (result == (size_t)-1) {
int error = errno;
}
It indeed fails, and error is filled with 92 (ENOPROTOOPT) - Protocol not available.
I've even tried setting the locale:
setlocale(LC_ALL, "C");
And this one too:
setlocale(LC_ALL, "");
I'm tempted to just throw the characters with static casts!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎问题在于源字符串是使用非标准编码(每个宽字符两个 ASCII 字符)进行编码的,这在调试器中看起来很好,但显然在内部很糟糕。生成的错误代码显然没有记录,但这相当于无法解码所述文本。
Seems the issue was that the source string was encoded with a non-standard encoding (two ASCII characters for each wide character), which looked fine in the debugger, but clearly internally was sour. The error code produced is clearly not documented, but it's the equivalent to simply not being able to decode said piece of text.