Namespaces
Variants

std:: wctob

From cppreference.net
헤더 파일에 정의됨 <cwchar>
int wctob ( std:: wint_t c ) ;

와이드 문자 c 를 초기 시프트 상태에서 해당하는 멀티바이트 문자가 단일 바이트인 경우 좁힙니다.

이는 일반적으로 ASCII 문자 집합의 문자들에 대해 가능합니다. 왜냐하면 대부분의 멀티바이트 인코딩(UTF-8과 같은)이 해당 문자들을 인코딩하기 위해 단일 바이트를 사용하기 때문입니다.

목차

매개변수

c - 와이드 문자를 좁은 문자로 변환

반환값

EOF 만약 c 가 초기 시프트 상태에서 길이가 1 인 멀티바이트 문자를 나타내지 않는 경우.

그렇지 않으면, c 의 싱글바이트 표현이 unsigned char 로서 int 로 변환됩니다.

예제

#include <clocale>
#include <cwchar>
#include <iostream>
void try_narrowing(wchar_t c)
{
    int cn = std::wctob(c);
    if (cn != EOF)
        std::cout << '\'' << int(c) << "' narrowed to " << +cn << '\n';
    else
        std::cout << '\'' << int(c) << "' could not be narrowed\n";
}
int main()
{
    std::setlocale(LC_ALL, "th_TH.utf8");
    std::cout << std::hex << std::showbase << "In Thai UTF-8 locale:\n";
    try_narrowing(L'a');
    try_narrowing(L'๛');
    std::setlocale(LC_ALL, "th_TH.tis620");
    std::cout << "In Thai TIS-620 locale:\n";
    try_narrowing(L'a');
    try_narrowing(L'๛');
}

출력:

In Thai UTF-8 locale:
'0x61' narrowed to 0x61
'0xe5b' could not be narrowed
In Thai TIS-620 locale:
'0x61' narrowed to 0x61
'0xe5b' narrowed to 0xfb

참고 항목

단일 바이트 좁은 문자를 와이드 문자로 확장합니다(가능한 경우)
(함수)
문자를 좁힙니다
( std::basic_ios<CharT,Traits> 의 public 멤버 함수)
do_narrow 를 호출합니다
( std::ctype<CharT> 의 public 멤버 함수)