std::mbsrtowcs
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cwchar> 中定义
|
||
std::size_t mbsrtowcs( wchar_t* dst, const char** src, |
||
。将一个空结束的多字节字符序列,该序列中所描述的
*ps
转换状态,从数组的第一个元素是指向*src
它的宽字符表示开始。 dst
不为空,转换字符被保存在连续的wchar_t数组元素所指向的dst
。以上len
宽字符写入到目标数组.原文:
Converts a null-terminated multibyte character sequence, which begins in the conversion state described by
*ps
, from the array whose first element is pointed to by *src
to its wide character representation. If dst
is not null, converted characters are stored in the successive elements of the wchar_t array pointed to by dst
. No more than len
wide characters are written to the destination array.。如果每个多字节字符转换为调用std::mbrtowc。的停止:转换。
原文:
Each multibyte character is converted as if by a call to std::mbrtowc. The conversion stops if:
- 。多字节的空字符被转换和存储。
src
设置为NULL*ps
初始位移状态.原文:The multibyte null character was converted and stored.src
is set to NULL and*ps
represents the initial shift state. - 。遇到了无效的多字节字符(根据目前的C语言环境)。
src
被设置为指向的第一个未转化的多字节字符开始.....原文:An invalid multibyte character (according to the current C locale) was encountered.src
is set to point at the beginning of the first unconverted multibyte character.
[编辑] 。参数。
dst | - | 。指针的结果将被储存到宽字符数组。
原文: pointer to wide character array where the results will be stored |
src | - | 。 null结尾的多字节字符串的第一个元素的指针的指针。
原文: pointer to pointer to the first element of a null-terminated multibyte string |
len | - | 。指出,DST的宽字符数组中的数。
原文: number of wide characters available in the array pointed to by dst |
ps | - | 。转换状态对象的指针。
原文: pointer to the conversion state object |
===。 返回值。===
。如果成功,则返回的宽字符数,不包括终止L'\0',写入的字符数组..如果dst==NULL,会被写入给定的无限长的宽字符数返回.
原文:
On success, returns the number of wide characters, excluding the terminating L'\0', written to the character array.. If dst==NULL, returns the number of wide characters that would have been written given unlimited length.
。在转换错误(如果遇到了无效的多字节字符),返回static_cast<std::size_t>(-1),店EILSEQerrno不明确的状态,并留下*ps.
原文:
On conversion error (if invalid multibyte character was encountered), returns static_cast<std::size_t>(-1), stores EILSEQ in errno, and leaves *ps in unspecified state.
[编辑] 。为例。
#include <iostream> #include <vector> #include <clocale> #include <cwchar> void print_as_wide(const char* mbstr) { std::mbstate_t state = std::mbstate_t(); int len = 1 + std::mbsrtowcs(NULL, &mbstr, 0, &state); std::vector<wchar_t> wstr(len); std::mbsrtowcs(&wstr[0], &mbstr, wstr.size(), &state); std::wcout << "Wide string: " << &wstr[0] << '\n' << "The length, including '\\0': " << wstr.size() << '\n'; } int main() { std::setlocale(LC_ALL, "en_US.utf8"); const char* mbstr = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; print_as_wide(mbstr); }
输出:
Wide string: zß水𝄋 The length, including '\0': 5
[编辑] 。另请参阅。
下的多字节字符转换为宽字符,给定的状态中 原文: converts the next multibyte character to wide character, given state (函数) | |
宽字符串转换成窄的多字节字符串,给定的状态 原文: converts a wide string to narrow multibyte character string, given state (函数) | |
[虚]</div></div>
|
将字符串转换,如从文件读取时,从externT到Internt的 原文: converts a string from externT to internT, such as when reading from file (虚拟保护成员函数of std::codecvt )
|
C documentation for mbsrtowcs
|