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
What is the Linux equivalent of: MultiByteToWideChar & WideCharToMultiByte?
提问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 iconv
functions iconv_open
, iconv
and iconv_close
(say man 3 iconv_open
etc. 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
, iconv
and iconv_close
(例如man 3 iconv_open
文档中的等)。对于跨平台应用程序,请改用ICU等专用库。这些库已经包含它们自己的字符串类;没有必要包装std::wstring
。
回答by caf
mbtowc
and wctomb
are the most direct equivalents, but note that they operate on the multibyte character set corresponding to the current LC_CTYPE
locale (which can be changed with setlocale()
).
mbtowc
和wctomb
是最直接的等价物,但请注意,它们对与当前LC_CTYPE
语言环境相对应的多字节字符集进行操作(可以用 更改setlocale()
)。