std:: mbsinit
|
Défini dans l'en-tête
<cwchar>
|
||
|
int
mbsinit
(
const
std::
mbstate_t
*
ps
)
;
|
||
Si
ps
n'est pas un pointeur nul, la fonction
mbsinit
détermine si l'objet pointé de type
std::mbstate_t
décrit l'état de conversion initial.
Table des matières |
Notes
Bien qu'un std::mbstate_t initialisé à zéro représente toujours l'état de conversion initial, il peut exister d'autres valeurs de std::mbstate_t qui représentent également l'état de conversion initial.
Paramètres
| ps | - | pointeur vers l'objet std::mbstate_t à examiner |
Valeur de retour
0 si ps n'est pas un pointeur nul et ne représente pas l'état de conversion initial, valeur non nulle sinon.
Exemple
#include <clocale> #include <cwchar> #include <iostream> #include <string> int main() { // permet à mbrlen() de fonctionner avec l'encodage multioctet UTF-8 std::setlocale(LC_ALL, "en_US.utf8"); // encodage multioctet étroit UTF-8 std::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"; }
Sortie :
After processing the first 1 byte of 水 the conversion state is not initial After processing the remaining 2 bytes of 水, the conversion state is initial conversion state
Voir aussi
|
informations d'état de conversion nécessaires pour itérer sur les chaînes de caractères multioctets
(classe) |
|
|
Documentation C
pour
mbsinit
|
|