Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      btowc

      From cppreference.com
      <c‎ |string‎ |multibyte
       
       
       
       
      Defined in header<wchar.h>
      wint_t btowc(int c);
      (since C95)

      Widens a single-byte characterc (reinterpreted asunsignedchar) to its wide character equivalent.

      Most multibyte character encodings use single-byte codes to represent the characters from the ASCII character set. This function may be used to convert such characters towchar_t.

      Contents

      [edit]Parameters

      c - single-byte character to widen

      [edit]Return value

      WEOF ifc isEOF

      wide character representation ofc if(unsignedchar)c is a valid single-byte character in the initial shift state,WEOF otherwise.

      [edit]Example

      Run this code
      #include <stdio.h>#include <wchar.h>#include <locale.h>#include <assert.h> void try_widen(unsignedchar c){    wint_t w= btowc(c);if(w!= WEOF)printf("The single-byte character %#x widens to %#x\n", c, w);elseprintf("The single-byte character %#x failed to widen\n", c);} int main(void){char*loc=setlocale(LC_ALL,"lt_LT.iso88594");assert(loc);printf("In Lithuanian ISO-8859-4 locale:\n");    try_widen('A');    try_widen('\xdf');// German letter ß (U+00df) in ISO-8859-4    try_widen('\xf9');// Lithuanian letter ų (U+0173) in ISO-8859-4 setlocale(LC_ALL,"lt_LT.utf8");printf("In Lithuanian UTF-8 locale:\n");    try_widen('A');    try_widen('\xdf');    try_widen('\xf9');}

      Possible output:

      In Lithuanian ISO-8859-4 locale:The single-byte character 0x41 widens to 0x41The single-byte character 0xdf widens to 0xdfThe single-byte character 0xf9 widens to 0x173In Lithuanian UTF-8 locale:The single-byte character 0x41 widens to 0x41The single-byte character 0xdf failed to widenThe single-byte character 0xf9 failed to widen

      [edit]References

      • C11 standard (ISO/IEC 9899:2011):
      • 7.29.6.1.1 The btowc function (p: 441)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.24.6.1.1 The btowc function (p: 387)

      [edit]See also

      (C95)
      narrows a wide character to a single-byte narrow character, if possible
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/string/multibyte/btowc&oldid=76790"

      [8]ページ先頭

      ©2009-2025 Movatter.jp