std::toupper(3)
std::toupper π
okay so this is the C++ Standard Library manual page for std::toupper, and we're gonna make it make sense, bestie. β¨
πΈ NAME πΈ
std::toupper β std::toupper (the name section is just doing its little mirror selfie, no notes).
β¨ Synopsis β¨
Defined in header <cctype>:
int toupper( int ch );
This icon converts the given character to uppercase according to the character conversion rules defined by the currently installed C locale. Slay.
In the default "C" locale, the following lowercase letters abcdefghijklmnopqrstuvwxyz are replaced with the respective uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ. Cute.
π Parameters π
chβ the character to be converted. If the value ofchis not representable asunsigned charand does not equalEOF, the behavior is undefined. Not "oopsie" undefined, actual undefined, so don't play with that π.
π Return value π
The converted character, or ch if no uppercase version is defined by the current C locale. That's it, that's the return.
π¦ Notes π¦
Like all other functions from <cctype>, the behavior of std::toupper is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char:
char my_toupper(char ch)
{
return static_cast<char>(std::toupper(static_cast<unsigned char>(ch)));
}
Similarly, they should not be directly used with standard algorithms when the iterator's value type is char or signed char. Instead, convert the value to unsigned char first:
std::string str_toupper(std::string s)
{
std::transform(s.begin(), s.end(), s.begin(),
// static_cast<int(*)(int)>(std::toupper) // wrong
// [](int c){ return std::toupper(c); } // wrong
// [](char c){ return std::toupper(c); } // wrong
[](unsigned char c){ return std::toupper(c); } // correct
);
return s;
}
π₯ Example π₯
// Run this code
#include <cctype>
#include <clocale>
#include <iostream>
int main()
{
unsigned char c = '\xb8'; // the character ΕΎ in ISO-8859-15
// but ΒΈ (cedilla) in ISO-8859-1
std::setlocale(LC_ALL, "en_US.iso88591");
std::cout << std::hex << std::showbase;
std::cout << "in iso8859-1, toupper('0xb8') gives " << std::toupper(c) << '\n';
std::setlocale(LC_ALL, "en_US.iso885915");
std::cout << "in iso8859-15, toupper('0xb8') gives " << std::toupper(c) << '\n';
}
β Output β
in iso8859-1, toupper('0xb8') gives 0xb8
in iso8859-15, toupper('0xb8') gives 0xb4
π See also π
tolowerβ converts a character to lowercase (function).toupper(std::locale)β converts a character to uppercase using thectypefacet of a locale (function template).towupperβ converts a wide character to uppercase (function).- C documentation for
toupperβ yes bestie, the C docs are right there in the see-also list.
kisses and uppercase slay π this page is from http://cppreference.com, dated 2024.06.10, and it's the std::toupper(3) manual page out π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms