windows 什么是 Linux 等价物:MultiByteToWideChar & WideCharToMultiByte?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3277013/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:52:02  来源:igfitidea点击:

What is the Linux equivalent of: MultiByteToWideChar & WideCharToMultiByte?

c++windowslinuxunicodestdstring

提问by NSA

I am working with a class that wraps the std::wstring, this code needs to be cross platform, are there equivalents to the windows functions: MultiByteToWideChar & WideCharToMultiByte on linux?

我正在使用一个包装 std::wstring 的类,此代码需要跨平台,是否有与 windows 函数等效的函数:Linux 上的 MultiByteToWideChar & WideCharToMultiByte?

Thank you.

谢谢你。

回答by Philipp

The Linux equivalents are the iconvfunctions iconv_open, iconvand iconv_close(say man 3 iconv_openetc. for the documentation). For cross-platform applications, use dedicated libraries such as ICUinstead. Such libraries already contain their own string classes; there is no need to wrap std::wstring.

Linux 的等价物是iconv函数iconv_open, iconvand iconv_close(例如man 3 iconv_open文档中的等)。对于跨平台应用程序,请改用ICU等专用库。这些库已经包含它们自己的字符串类;没有必要包装std::wstring

回答by caf

mbtowcand wctombare the most direct equivalents, but note that they operate on the multibyte character set corresponding to the current LC_CTYPElocale (which can be changed with setlocale()).

mbtowcwctomb是最直接的等价物,但请注意,它们对与当前LC_CTYPE语言环境相对应的多字节字符集进行操作(可以用 更改setlocale())。