在 iOS 上将 wchar_t* 转换为 char*

发布于 2024-12-19 13:40:59 字数 377 浏览 4 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贱贱哒 2024-12-26 13:40:59

似乎问题在于源字符串是使用非标准编码(每个宽字符两个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文