Namespaces
Variants

std:: mbsinit

From cppreference.net
헤더 파일에 정의됨 <cwchar>
int mbsinit ( const std:: mbstate_t * ps ) ;

만약 ps 가 null 포인터가 아니라면, mbsinit 함수는 가리키는 std::mbstate_t 객체가 초기 변환 상태를 나타내는지 여부를 판단합니다.

목차

참고 사항

제로 초기화된 std::mbstate_t 가 항상 초기 변환 상태를 나타내지만, std::mbstate_t 의 다른 값들도 초기 변환 상태를 나타낼 수 있습니다.

매개변수

ps - 검사할 std::mbstate_t 객체를 가리키는 포인터

반환값

0 만약 ps 가 null 포인터가 아니고 초기 변환 상태를 나타내지 않는 경우, 그 외의 경우에는 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 documentation for mbsinit