std::mbstowcs
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cstdlib> 中定义
|
||
std::size_t mbstowcs( wchar_t* dst, const char* src, std::size_t len) |
||
。转换一个多字节字符串数组,该数组的第一个元素是指向
src
它的宽字符表示。转换的字符存储在连续元素指向的数组由dst
。以上len
宽字符写入到目标数组.原文:
Converts a multibyte character string from the array whose first element is pointed to by
src
to its wide character representation. Converted characters are stored in the successive elements of the array pointed to by dst
. No more than len
wide characters are written to the destination array.。每个字符被转换为如果由呼叫std::mbtowc,除了的mbtowc转换状态不受影响。的停止:转换。
原文:
Each character is converted as if by a call to std::mbtowc, except that the mbtowc conversion state is unaffected. The conversion stops if:
- 。多字节的空字符被转换并存储.原文:The multibyte null character was converted and stored.
- 。遇到一个无效的(在当前的C语言环境)的多字节字符.原文:An invalid (in the current C locale) multibyte character was encountered.
- 。下一个宽字符存储将超过
len
.....原文:The next wide character to be stored would exceedlen
.
目录 |
[编辑] 。注释。
。在大多数实现中,这个函数更新一个全局静态std::mbstate_t类型的对象,因为它处理通过字符串,并不能同时由两个线程调用,std::mbsrtowcs应在这种情况下,使用.
原文:
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::mbsrtowcs should be used in such cases.
。 POSIX指定一个常见的扩展:如果
dst
是一个空指针,这个函数返回的数量范围内的字符将被写入到dst
,如果转换。类似的行为标准std::mbsrtowcs原文:
POSIX specifies a common extension: if
dst
is a null pointer, this function returns the number of wide characters that would be written to dst
, if converted. Similar behavior is standard for std::mbsrtowcs.[编辑] 。参数。
dst | - | 。宽字符串将被存储到宽字符数组的指针。
原文: pointer to wide character array where the wide string will be stored |
src | - | 。 null结尾的多字节字符串转换的第一个元素的指针。
原文: pointer to the first element of a null-terminated multibyte string to convert |
len | - | 。指出,DST的宽字符数组中的数。
原文: number of wide characters available in the array pointed to by dst |
===。 返回值。===
。成功时,返回的宽字符数,不包括终止L'\0',写入到目标数组.
原文:
On success, returns the number of wide characters, excluding the terminating L'\0', written to the destination array.
。转换错误(如果遇到了无效的多字节字符),返回-1.
原文:
On conversion error (if invalid multibyte character was encountered), returns -1.
[编辑] 。为例。
#include <iostream> #include <clocale> #include <cstdlib> 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"; wchar_t wstr[5]; std::mbstowcs(wstr, mbstr, 5); std::wcout << "wide string: " << wstr << '\n'; }
输出:
wide string: zß水𝄋
[编辑] 。另请参阅。
将一个狭窄的多字节字符的字符串,宽字符串,给定的状态 原文: converts a narrow multibyte character string to wide string, given state (函数) | |
缩小的多字节字符串转换成宽字符串 原文: converts a wide string to narrow multibyte character string (函数) | |
[虚]</div></div>
|
将字符串转换,如从文件读取时,从externT到Internt的 原文: converts a string from externT to internT, such as when reading from file (虚拟保护成员函数of std::codecvt )
|
C documentation for mbstowcs
|