Localization library | |||||||||||||||||||||||||
Regular expressions library(C++11) | |||||||||||||||||||||||||
Formatting library(C++20) | |||||||||||||||||||||||||
Null-terminated sequence utilities | |||||||||||||||||||||||||
Byte strings | |||||||||||||||||||||||||
Multibyte strings | |||||||||||||||||||||||||
Wide strings | |||||||||||||||||||||||||
Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Text encoding identifications | |||||||||||||||||||||||||
|
Defined in header <cwchar> | ||
int mbsinit(conststd::mbstate_t* ps); | ||
Ifps is not a null pointer, thembsinit
function determines whether the pointed-tostd::mbstate_t object describes the initial conversion state.
Contents |
Although a zero-initializedstd::mbstate_t always represents the initial conversion state, there may be other values ofstd::mbstate_t that also represent the initial conversion state.
ps | - | pointer to thestd::mbstate_t object to examine |
0 ifps is not a null pointer and does not represent the initial conversion state, nonzero value otherwise.
#include <clocale>#include <cwchar>#include <iostream>#include <string> int main(){// allow mbrlen() to work with UTF-8 multibyte encodingstd::setlocale(LC_ALL,"en_US.utf8");// UTF-8 narrow multibyte encodingstd::string str="水";// or u8"\u6c34" or "\xe6\xb0\xb4"std::mbstate_t mb=std::mbstate_t();(void)std::mbrlen(&str[0],1,&mb);if(!std::mbsinit(&mb))std::cout<<"After processing the first 1 byte of "<< str<<" the conversion state is not initial\n"; (void)std::mbrlen(&str[1], str.size()-1,&mb);if(std::mbsinit(&mb))std::cout<<"After processing the remaining 2 bytes of "<< str<<", the conversion state is initial conversion state\n";}
Output:
After processing the first 1 byte of 水 the conversion state is not initialAfter processing the remaining 2 bytes of 水, the conversion state is initial conversion state
conversion state information necessary to iterate multibyte character strings (class)[edit] | |
C documentation formbsinit |