CKTIS / C++
std::uppercase — uppercase letters in numeric output
std::uppercase is a stream manipulator that selects uppercase letters in formatted numeric output, such as hexadecimal digits A–F and the exponent marker E. It does not transform text or select a number base; the setting remains active until changed.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
#include <ios>
std::ios_base& std::uppercase(std::ios_base& str);
stream << std::uppercase;std::uppercase, declared in <ios>, is a stream formatting manipulator used without parentheses: stream << std::uppercase. It calls str.setf(std::ios_base::uppercase) and returns the same stream. std::uppercase is a function, whereas std::ios_base::uppercase is a formatting flag.
For hexadecimal output, it selects digits A–F instead of a–f. When a prefix is enabled by std::showbase, it uses 0X instead of 0x. For floating-point output, it selects, among other things, E instead of e in scientific notation and uppercase letters in hexadecimal notation.
The manipulator changes letter case, not the number base. Integers are written in hexadecimal when the stream’s std::ios_base::basefield is set to std::ios_base::hex. If it is already set to that value, no change is needed; otherwise, use std::hex or call stream.setf(std::ios_base::hex, std::ios_base::basefield). The manipulator does not uppercase letters in strings or characters being written, nor does it change the Boolean names written with std::boolalpha.
The flag belongs to the particular stream and stays set for subsequent operations, including across line endings. std::nouppercase clears it but does not reset other settings such as std::hex or std::showbase. If a function must preserve earlier formatting, save auto saved = stream.flags(); and later restore it with stream.flags(saved);.
Examples
#include <ios>
#include <iostream>
#include <locale>
#include <sstream>
int main() {
std::ostringstream out;
out.imbue(std::locale::classic());
out << std::hex << std::showbase
<< std::uppercase << 48879 << ' ' << 26 << '\n'
<< std::nouppercase << 48879 << '\n';
std::cout << out.str();
}
Result
0XBEEF 0X1A 0xbeef
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.