Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::wctob

      From cppreference.com
      <cpp‎ |string‎ |multibyte
       
       
       
       
      Defined in header<cwchar>
      int wctob(std::wint_t c);

      Narrows a wide characterc if its multibyte character equivalent in the initial shift state is a single byte.

      This is typically possible for the characters from the ASCII character set, since most multibyte encodings (such as UTF-8) use single bytes to encode those characters.

      Contents

      [edit]Parameters

      c - wide character to narrow

      [edit]Return value

      EOF ifc does not represent a multibyte character with length1 in initial shift state.

      Otherwise, the single-byte representation ofc asunsignedchar converted toint.

      [edit]Example

      Run this code
      #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';elsestd::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'๛');}

      Output:

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

      [edit]See also

      widens a single-byte narrow character to wide character, if possible
      (function)[edit]
      narrows characters
      (public member function ofstd::basic_ios<CharT,Traits>)[edit]
      invokesdo_narrow
      (public member function ofstd::ctype<CharT>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/multibyte/wctob&oldid=153090"

      [8]ページ先頭

      ©2009-2025 Movatter.jp