| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
ctype::toupperctype::do_toupper | ||||
| Member functions of ctype<char> | ||||
Defined in header <locale> | ||
public: CharT toupper( CharT c)const; | (1) | |
public: const CharT* toupper( CharT* beg,const CharT* end)const; | (2) | |
protected: virtual CharT do_toupper( CharT c)const; | (3) | |
protected: virtualconst CharT* do_toupper( CharT* beg,const CharT* end)const; | (4) | |
do_toupper of the most derived class.[beg, end), for which an upper case form exists, replaces the character with that upper case form.Contents |
| c | - | character to convert |
| beg | - | pointer to the first character in an array of characters to convert |
| end | - | one past the end pointer for the array of characters to convert |
Only 1:1 character mapping can be performed by this function, e.g. the uppercase form of 'ß' is the two-character string "SS" (with some exceptions - see«Capital ẞ»), which cannot be obtained bydo_toupper.
#include <iostream>#include <locale> void try_upper(conststd::ctype<wchar_t>& f,wchar_t c){wchar_t up= f.toupper(c);if(up!= c)std::wcout<<"Upper case form of\'"<< c<<"' is "<< up<<'\n';elsestd::wcout<<'\''<< c<<"' has no upper case form\n";} int main(){std::locale::global(std::locale("en_US.utf8"));std::wcout.imbue(std::locale());std::wcout<<"In US English UTF-8 locale:\n";auto& f=std::use_facet<std::ctype<wchar_t>>(std::locale()); try_upper(f, L's'); try_upper(f, L'ſ'); try_upper(f, L'δ'); try_upper(f, L'ö'); try_upper(f, L'ß'); std::wstring str= L"Hello, World!";std::wcout<<"Uppercase form of the string '"<< str<<"' is "; f.toupper(&str[0],&str[0]+ str.size());std::wcout<<'\''<< str<<"'\n";}
Output:
In US English UTF-8 locale:Upper case form of 's' is SUpper case form of 'ſ' is SUpper case form of 'δ' is ΔUpper case form of 'ö' is Ö'ß' has no upper case formUppercase form of the string 'Hello, World!' is 'HELLO, WORLD!'
invokesdo_tolower(public member function)[edit] | |
| converts a character to uppercase (function)[edit] | |
| converts a wide character to uppercase (function)[edit] |