std::wcsrtombs
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <cwchar> 中定义
|
||
| std::size_t wcsrtombs( char* dst, const wchar_t** src, |
||
。转换序列的宽字符数组,该数组的第一个元素是指向
*src窄的多字节表示,开始在*ps所描述的转换状态。 dst不为空,转换字符被保存在连续的char数组的元素所指向的dst。不超过len字节写入到目标数组.原文:
Converts a sequence of wide characters from the array whose first element is pointed to by
*src to its narrow multibyte representation that begins in the conversion state described by *ps. If dst is not null, converted characters are stored in the successive elements of the char array pointed to by dst. No more than len bytes are written to the destination array.。如果每个字符被转换为调用std::wcrtomb。的停止:转换。
原文:
Each character is converted as if by a call to std::wcrtomb. The conversion stops if:
- 。空字符转换和存储。
src设置为NULL*ps初始位移状态.原文:The null character was converted and stored.srcis set to NULL and*psrepresents the initial shift state. - 。一个wchar_t发现不符合当前的C语言环境中的有效字符。
src被设置为指向第一个未转换的宽字符.原文:A wchar_t was found that does not correspond to a valid character in the current C locale.srcis set to point at the first unconverted wide character.
[编辑] 。参数。
| dst | - | 。窄的多字节字符的字符数组将被存储的指针。
原文: pointer to narrow character array where the multibyte characters will be stored |
| src | - | 。一个空结尾的宽字符串的第一个元素的指针的指针。
原文: pointer to pointer to the first element of a null-terminated wide string |
| len | - | 。字节数组中的数指出,DST。
原文: number of bytes available in the array pointed to by dst |
| ps | - | 。转换状态对象的指针。
原文: pointer to the conversion state object |
===。 返回值。===
。如果成功,则返回的字节数(包括任何移位序列,但不包括终止'\0'),写入的字符数组,该数组的第一个元素是指向
dst。如果dst==NULL,返回会被写入的字节数.原文:
On success, returns the number of bytes (including any shift sequences, but excluding the terminating '\0') written to the character array whose first element is pointed to by
dst. If dst==NULL, returns the number of bytes that would have been written.。如果遇到无效的宽字符转换错误(),返回static_cast<std::size_t>(-1),店EILSEQerrno不明确的状态,并留下*ps.
原文:
On conversion error (if invalid wide 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 <string> #include <cwchar> void print_wide(const wchar_t* wstr) { std::mbstate_t state = std::mbstate_t(); int len = 1 + std::wcsrtombs(NULL, &wstr, 0, &state); std::vector<char> mbstr(len); std::wcsrtombs(&mbstr[0], &wstr, mbstr.size(), &state); std::cout << "multibyte string: " << &mbstr[0] << '\n' << "Length, including '\\0': " << mbstr.size() << '\n'; } int main() { std::setlocale(LC_ALL, "en_US.utf8"); // UTF-8 narrow multibyte encoding const wchar_t* wstr = L"z\u00df\u6c34\U0001d10b"; // or L"zß水𝄋" print_wide(wstr); }
输出:
multibyte string: zß水𝄋 Length, including '\0': 11
[编辑] 。另请参阅。
| 一个宽字符转换为多字节表示,给定的状态 原文: converts a wide character to its multibyte representation, given state (函数) | |
| 将一个狭窄的多字节字符的字符串,宽字符串,给定的状态 原文: converts a narrow multibyte character string to wide string, given state (函数) | |
| [虚]</div></div>
|
转换成一个字符串,如写入文件时,从Internt的externT 原文: converts a string from internT to externT, such as when writing to file (虚拟保护成员函数of std::codecvt)
|
| C documentation for wcsrtombs
| |