std::mbtowc

来自cppreference.com

 
 
字符串库
null结尾的字符串
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
字节的字符串
多字节字符串
宽字符串
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string
char_traits
 
NULL结尾的多字节字符串
宽/多字节转换
Original:
Wide/multibyte conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mbsinit
mbtowc
mbstowcs
btowc
mbrtowc
mbsrtowcs
mbrtoc16(C++11)
mbrtoc32(C++11)
mblen
类型
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mbstate_t
 
Defined in header <cstdlib>
int mbtowc( wchar_t* pwc, const char* s, std::size_t n )
。转换一个多字节字符的第一个字节指出,s为宽字符,写入*pwcpwc不为空.
Original:
Converts a multibyte character whose first byte is pointed to by s to a wide character, written to *pwc if pwc is not null.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
。如果s是一个空指针,将全局转换状态,并确定是否使用了移位序列.
Original:
If s is a null pointer, resets the global conversion state and determines whether shift sequences are used.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目录

[编辑] 。参数。

s -
。多字节字符的指针。
Original:
pointer to the multibyte character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n -
。限制的字节数,可以检查。
Original:
limit on the number of bytes in s that can be examined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pwc -
。用于输出的宽字符指针。
Original:
pointer to the wide character for output
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

===。 返回值。===

。如果s是不是一个空指针,返回的字节数中所包含的多字节字符或-1如果第一个字节所指向的s没有形成一个有效的多字节字符或0如果s指向空字符内'\0',.
Original:
If s is not a null pointer, returns the number of bytes that are contained in the multibyte character or -1 if the first bytes pointed to by s do not form a valid multibyte character or 0 if s is pointing at the null charcter '\0'.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
。如果s是一个空指针,将其内部的转换状态来表示的初始变速状态,并返回0如果当前的多字节编码不是状态依赖(不使用移位序列)或一个非零的值,如果当前的多字节编码是状态依赖(使用Shift序列).
Original:
If s is a null pointer, resets its internal conversion state to represent the initial shift state and returns 0 if the current multibyte encoding is not state-dependent (does not use shift sequences) or a non-zero value if the current multibyte encoding is state-dependent (uses shift sequences).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 。注释。

。每次调用mbtowc更新的内部全局转换状态(静态std::mbstate_t类型的对象,只知道此功能)。如果多字节编码使用上档状态,必须小心,以避免回溯或多次扫描。在任何情况下,多线程不应该叫mbtowc不同​​步:std::mbrtowc可以用来代替.
Original:
Each call to mbtowc updates the internal global conversion state (a static object of type std::mbstate_t, only known to this function). If the multibyte encoding uses shift states, care must be taken to avoid backtracking or multiple scans. In any case, multiple threads should not call mbtowc without synchronization: std::mbrtowc may be used instead.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[编辑] 。为例。

#include <iostream>
#include <clocale>
#include <cstring>
#include <cstdlib>
 
int print_mb(const char* ptr)
{
    std::mbtowc(NULL, 0, 0); // reset the conversion state
    const char* end = ptr + std::strlen(ptr);
    int ret;
    for (wchar_t wc; (ret = std::mbtowc(&wc, ptr, end-ptr)) > 0; ptr+=ret) {
        std::wcout << wc;
    }
    std::wcout << '\n';
    return ret;
}
 
int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    const char* str = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋"
                      // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
    print_mb(str);
}

Output:

zß水𝄋

[编辑] 。另请参阅。

下的多字节字符转换为宽字符,给定的状态中
Original:
converts the next multibyte character to wide character, given state
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(函数) [edit]
在未来的多字节字符,返回的字节数
Original:
returns the number of bytes in the next multibyte character
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(函数) [edit]
[虚拟的] </ SPAN></div></div>
将字符串转换,如从文件读取时,从externT到Internt的
Original:
converts a string from externT to internT, such as when reading from file
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(虚拟保护成员函数of std::codecvt [edit]
C documentation for mbtowc
来自“http://zh.cppreference.com/mwiki/index.php?title=cpp/string/multibyte/mbtowc&oldid=27028