std::wcstombs
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cstdlib> 中定义
|
||
std::size_t wcstombs( char* dst, const wchar_t* src, std::size_t len) |
||
。从阵列中的第一元件被指出通过
src
其窄的多字节表示开始在初始变速状态的宽字符的序列转换。转换的字符存储在连续元素的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 initial shift state. 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::wctomb,除了wctomb的转换状态不受影响。的停止:转换。
原文:
Each character is converted as if by a call to std::wctomb, except that the wctomb's conversion state is unaffected. The conversion stops if:
- 。空字符转换和存储.原文:The null character was converted and stored.
- 。 一个wchar_t发现不符合当前的C语言环境中的有效字符.原文:A wchar_t was found that does not correspond to a valid character in the current C locale.
- 。接下来的多字节字符存储将超过
len
.原文:The next multibyte character to be stored would exceedlen
.
目录
[编辑] 。注释。
。在大多数实现中,这个函数更新一个全局静态std::mbstate_t类型的对象,因为它处理通过字符串,并不能同时由两个线程调用,std::wcsrtombs应在这种情况下,使用.原文:In most implementations, this function updates a global static object of type std::mbstate_t as it processes through the string, and cannot be called simultaneously by two threads, std::wcsrtombs should be used in such cases.。 POSIX指定一个常见的扩展:如果dst
是一个空指针,这个函数返回的字节将被写入到dst
,如果转换。类似的行为标准std::wcsrtombs原文:POSIX specifies a common extension: ifdst
is a null pointer, this function returns the number of bytes that would be written todst
, if converted. Similar behavior is standard for std::wcsrtombs.[编辑] 。参数。
dst - 。窄字符数组的多字节字符将被存储的指针。原文:pointer to narrow character array where the multibyte character will be storedsrc - 。指针转换成一个空结尾的宽字符串的第一个元素。原文:pointer to the first element of a null-terminated wide string to convertlen - 。数所指向的字节数组中的DST。原文:number of byte available in the array pointed to by dst===。 返回值。===
。如果成功,则返回的字节数(包括任何移位序列,但不包括终止'\0'),写入的字符数组,该数组的第一个元素是指向dst
.原文: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 bydst
.。转换错误(如果遇到无效的宽字符),返回static_cast<std::size_t>(-1).原文:On conversion error (if invalid wide character was encountered), returns static_cast<std::size_t>(-1).[编辑] 。为例。
#include <iostream> #include <clocale> #include <cstdlib> 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ß水𝄋" char mbstr[11]; std::wcstombs(mbstr, wstr, 11); std::cout << "multibyte string: " << mbstr << '\n'; }
输出:
multibyte string: zß水𝄋
[编辑] 。另请参阅。
宽字符串转换成窄的多字节字符串,给定的状态原文:converts a wide string to narrow multibyte character string, given state
(函数)多字节字符串转换成一个狭窄的宽字符串原文:converts a narrow multibyte character string to wide string
(函数)[虚]</div></div>转换成一个字符串,如写入文件时,从Internt的externT原文:converts a string from internT to externT, such as when writing to file
(虚拟保护成员函数ofstd::codecvt
)C documentation for wcstombs -