Home C++ Iostream Functions uppercase C++ uppercase Manipulator Definition In C++, uppercase makes a stream use capital letters when it prints numbers. Hexadecimal digits come out as A to F, the prefix becomes 0X, and the exponent in scientific notation uses E.
Only the letters that belong to a number change. Normal text is never affected. It comes from <ios>, which <iostream> includes.
This is a manipulator . You do not call it on its own. You send it into a stream with << or >>, and it changes how that stream behaves from then on (or does one small job, like ending a line).
Syntax Put std::uppercase into the stream before the numbers.
std::cout << std::hex << std::uppercase << 255; // FF
std::cout << std::scientific << std::uppercase << 1500.0; // 1.500000E+03 Call What it does std::cout << std::uppercaseCapital letters in numbers from now on. std::cout << std::hex << std::uppercase << 255Prints FF. std::cout << std::scientific << std::uppercase << 1500.0Prints 1.500000E+03.
Strings such as "hello" are not changed by uppercase. Use std::toupper for text.
Library declarations ios_base& uppercase(ios_base& str); Parameters Parameter Description strThe stream. It is passed in for you when you write cout << uppercase. You never write this argument yourself.
Return Value Return Value Description ios_base&A reference to the same stream, so you can keep chaining << or >> after uppercase.
Important
uppercase stays on until you call nouppercase. It does not make text capital, it affects only hex digits, the 0x prefix, and the e of exponents.
C++ Examples 1. Hex digits 2. Scientific 3. Hex word Example 1 — Print Hex with Capital Letters The same number with and without uppercase.
#include <iostream>
int main() {
std::cout << std::hex << 255 << '\n';
std::cout << std::uppercase << 255 << '\n';
return 0;
} How It Works std::hex prints 255 as ff, using small letters by default.std::uppercase switches the letters to capitals and stays active.The second line prints the same number as FF. Example 2 — Capital E in Scientific Notation The letter of the exponent also becomes a capital.
#include <iostream>
int main() {
std::cout << std::scientific;
std::cout << 12345.678 << '\n';
std::cout << std::uppercase << 12345.678 << '\n';
return 0;
} 1.234568e+04
1.234568E+04 How It Works std::scientific prints a number as a digit, a point, and a power of ten.By default the exponent letter is a small e: 1.234568e+04. With uppercase it becomes E, so the second line is 1.234568E+04. Example 3 — Print a Hex Word A famous hex number spells a word, but only in capitals.
#include <iostream>
int main() {
int value = 48879;
std::cout << std::hex << std::uppercase << value << '\n';
std::cout << std::nouppercase << value << '\n';
return 0;
} How It Works 48879 written in base 16 is BEEF.With uppercase on, the letters B, E, and F are capitals. nouppercase turns the setting off again, so the second line is beef.Frequently Asked Questions What does uppercase do in C++? It makes numbers print with capital letters: hex digits A to F, the 0X prefix, and the E in scientific notation.
Does uppercase change normal text? No. A string like "hello" is printed as it is. Use std::toupper to change letters in text.
How do I print hex numbers like FF? Use std::hex and std::uppercase together: cout << hex << uppercase << 255.
How do I turn uppercase off? Use std::nouppercase or cout.unsetf(std::ios::uppercase).
Does uppercase affect decimal numbers? No. Decimal numbers have no letters, unless they are printed in scientific notation, where it changes the e.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
11 people found this page helpful
Helpful Share Copy link Suggestion