Namespaces
Variants
Views
Actions

std::towupper

From cppreference.com
< cpp‎ | string‎ | wide
Revision as of 06:51, 10 June 2023 by Andreas Krug (Talk | contribs)

Defined in header <cwctype>
std::wint_t towupper( std::wint_t ch );

Converts the given wide character to uppercase, if possible.

If the value of ch is neither representable as a wchar_t nor equal to the value of the macro WEOF, the behavior is undefined.

Contents

Parameters

ch - wide character to be converted

Return value

Uppercase version of ch or unmodified ch if no uppercase version is listed in the current C locale.

Notes

Only 1:1 character mapping can be performed by this function, e.g. the uppercase form of 'ß' is (with some exceptions) the two-character string "SS", which cannot be obtained by std::towupper.

ISO 30112 specifies which pairs of Unicode characters are included in this mapping.

Example

The latin letter 'ſ' (U+017F) is the alternative lowercase form of 'S' (U+0053).

#include <clocale>
#include <cwctype>
#include <iostream>
 
int main()
{
    wchar_t c = L'\u017f'; // Latin small letter Long S ('ſ')
 
    std::cout << std::hex << std::showbase;
    std::cout << "in the default locale, towupper(" << (std::wint_t)c << ") = "
              << std::towupper(c) << '\n';
    std::setlocale(LC_ALL, "en_US.utf8");
    std::cout << "in Unicode locale, towupper(" << (std::wint_t)c << ") = "
              << std::towupper(c) << '\n';
}

Output:

in the default locale, towupper(0x17f) = 0x17f
in Unicode locale, towupper(0x17f) = 0x53

See also

converts a wide character to lowercase
(function) [edit]
converts a character to uppercase using the ctype facet of a locale
(function template) [edit]
converts a character to uppercase
(function) [edit]
C documentation for towupper