名前空間
変種
操作

std::mbsinit

From cppreference.com
< cpp‎ | string‎ | multibyte
 
 
 
 
ヘッダ <cwchar> で定義
int mbsinit( const std::mbstate_t* ps);

もし ps がヌルポインタでない場合、mbsinit 関数は、指し示されている std::mbstate_t オブジェクトが初期変換状態を表しているかどうかを判定します。

目次

[編集] 注記

ゼロ初期化された std::mbstate_t は常に初期変換状態を表しますが、初期変換状態を表す他の値も存在する可能性があります。

[編集] パラメータ

ps - 検査する std::mbstate_t オブジェクトへのポインタ

[編集] 戻り値

0: ps がヌルポインタでなく、初期変換状態を表さない場合。それ以外の場合は非ゼロ値。

[編集]

#include <clocale>
#include <cwchar>
#include <iostream>
#include <string>
 
int main()
{
    // allow mbrlen() to work with UTF-8 multibyte encoding
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    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";
}

出力

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

[編集] 関連項目

マルチバイト文字列を走査するために必要な変換状態情報
(クラス) [編集]
English 日本語 中文(简体) 中文(繁體)