std::mbsinit
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <cwchar> で定義
|
||
int mbsinit( const std::mbstate_t* ps); |
||
ps がヌルポインタでなければ、指されている std::mbstate_t オブジェクトが初期変換状態を表すかどうかを調べます。
ノート
ゼロ初期化された std::mbstate_t は必ず初期変換状態を表しますが、初期変換状態を表す他の std::mbstate_t の値も存在するかもしれません。
引数
| ps | - | 調べる std::mbstate_t オブジェクトを指すポインタ |
戻り値
ps がヌルでなく、初期変換状態を表さない場合は 0。 そうでなければ非ゼロの値。
例
Run this code
#include <clocale>
#include <string>
#include <iostream>
#include <cwchar>
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 = u8"水"; // 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
関連項目
| マルチバイト文字列を反復処理するために必要な変換状態情報 (クラス) | |
mbsinit の C言語リファレンス
| |