Namespaces
Variants
Views
Actions

std::wctob

From cppreference.com
< cpp‎ | string‎ | multibyte
Revision as of 06:59, 14 May 2012 by P12 (Talk | contribs)

Template:cpp/string/multibyte/sidebar

Defined in header <cwchar>
int wctob( std::wint_t c );

Narrows a wide character c 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

Parameters

c - wide character to narrow

Return value

EOF if c does not represent a multibyte character with length 1 in initial shift state.

Otherwise, the single-byte representation of c as unsigned char converted to int

Example

#include <cwchar>
#include <cstdio>
#include <clocale>
 
int main()
{
    std::setlocale(LC_ALL, "");
    std::printf("narrow: %c\nnarrowed from wide: %c\n", 'a', std::wctob(L'a'));
}

Output:

narrow: a
narrowed from wide: a

See also

Template:cpp/string/multibyte/dcl list btowcTemplate:cpp/locale/ctype/dcl list do narrow
C documentation for wctob