std::mbsinit
來自 cppreference.com
在標頭檔案 <cwchar> 中定義 |
||
int mbsinit( const std::mbstate_t* ps); |
||
如果 ps 不是空指標,則 mbsinit
函式確定指向的 std::mbstate_t 物件是否描述了初始轉換狀態。
目錄 |
[編輯] 注意
儘管零初始化的 std::mbstate_t 總是表示初始轉換狀態,但 std::mbstate_t 可能還有其他值也表示初始轉換狀態。
[編輯] 引數
ps | - | 指向要檢查的 std::mbstate_t 物件的指標 |
[編輯] 返回值
如果 ps 不是空指標且不表示初始轉換狀態,則返回 0,否則返回非零值。
[編輯] 示例
執行此程式碼
#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
[編輯] 另請參閱
迭代多位元組字串所需的轉換狀態資訊 (類) | |
C 文件 中關於 mbsinit 的內容
|