std::wcrtomb
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cwchar> 中定义
|
||
std::size_t wcrtomb( char* s, wchar_t wc, std::mbstate_t* ps ); |
||
。一个宽字符转换成窄的多字节表示.
原文:
Converts a wide character to its narrow multibyte representation.
。
s
是不是一个空指针,函数的数量决定了需要存储的字节的多字节字符表示wc
(包括任何移位序列),和存储多字节字符表示的字符数组,该数组的第一个元素是指向s
。通过此功能可以写在最MB_CUR_MAX字节.原文:
If
s
is not a null pointer, the function determines the number of bytes necessary to store the multibyte character representation of wc
(including any shift sequences), and stores the multibyte character representation in the character array whose first element is pointed to by s
. At most MB_CUR_MAX bytes can be written by this function.。
s
是一个空指针,调用等效std::wcrtomb(buf, L'\0', ps)一些内部缓冲区buf
.原文:
If
s
is a null pointer, the call is equivalent to std::wcrtomb(buf, L'\0', ps) for some internal buffer buf
.。 ,如果WC是空的宽字符L'\0',空字节存储,在此之前通过必要的任何变化序列,恢复初始移位状态的更新和转换状态参数*ps代表初始位移状态的.
原文:
If wc is the null wide character L'\0', a null byte is stored, preceded by any shift sequence necessary to restore the initial shift state and the conversion state parameter *ps is updated to represent the initial shift state.
[编辑] 。参数。
s | - | 。窄字符数组的多字节字符将被存储的指针。
原文: pointer to narrow character array where the multibyte character will be stored |
wc | - | 。宽字符转换。
|
ps | - | 。解释的多字节字符串时使用的转换状态对象的指针。
原文: pointer to the conversion state object used when interpreting the multibyte string |
===。 返回值。===
。如果成功,则返回写入的字符数组,该数组的第一个元素是指向
s
的字节数(包括任何移位序列). 原文:
On success, returns the number of bytes (including any shift sequences) written to the character array whose first element is pointed to by
s
. 。失败(如果wc是不是一个有效的宽字符),返回static_cast<std::size_t>(-1),店EILSEQerrno不明确的状态,并留下*ps.
原文:
On failure (if wc is not a valid wide character), returns static_cast<std::size_t>(-1), stores EILSEQ in errno, and leaves *ps in unspecified state.
[编辑] 。为例。
#include <iostream> #include <clocale> #include <string> #include <cwchar> void print_wide(const std::wstring& wstr) { std::mbstate_t state = std::mbstate_t(); for(wchar_t wc : wstr) { std::string mb(MB_CUR_MAX, '\0'); int ret = std::wcrtomb(&mb[0], wc, &state); std::cout << "multibyte char " << mb << " is " << ret << " bytes\n"; } } int main() { std::setlocale(LC_ALL, "en_US.utf8"); // UTF-8 narrow multibyte encoding std::wstring wstr = L"z\u00df\u6c34\U0001d10b"; // or L"zß水𝄋" print_wide(wstr); }
输出:
multibyte char z is 1 bytes multibyte char ß is 2 bytes multibyte char 水 is 3 bytes multibyte char 𝄋 is 4 bytes
[编辑] 。另请参阅。
一个宽字符转换成多字节表示 原文: converts a wide character to its multibyte representation (函数) | |
下的多字节字符转换为宽字符,给定的状态中 原文: converts the next multibyte character to wide character, 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 wcrtomb
|