C++ uppercase Manipulator

Beginner
5 min read
Updated: Nov 2026
3 examples
iostream

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.

C++
std::cout << std::hex << std::uppercase << 255;       // FF
std::cout << std::scientific << std::uppercase << 1500.0;   // 1.500000E+03
CallWhat 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
C++
ios_base& uppercase(ios_base& str);

Parameters

ParameterDescription
strThe stream. It is passed in for you when you write cout << uppercase. You never write this argument yourself.

Return Value

Return ValueDescription
ios_base&A reference to the same stream, so you can keep chaining << or >> after uppercase.

C++ Examples

Example 1 — Print Hex with Capital Letters

The same number with and without uppercase.

C++
#include <iostream>

int main() {
    std::cout << std::hex << 255 << '\n';
    std::cout << std::uppercase << 255 << '\n';
    return 0;
}

How It Works

  1. std::hex prints 255 as ff, using small letters by default.
  2. std::uppercase switches the letters to capitals and stays active.
  3. 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.

C++
#include <iostream>

int main() {
    std::cout << std::scientific;
    std::cout << 12345.678 << '\n';
    std::cout << std::uppercase << 12345.678 << '\n';
    return 0;
}

How It Works

  1. std::scientific prints a number as a digit, a point, and a power of ten.
  2. By default the exponent letter is a small e: 1.234568e+04.
  3. 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.

C++
#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

  1. 48879 written in base 16 is BEEF.
  2. With uppercase on, the letters B, E, and F are capitals.
  3. nouppercase turns the setting off again, so the second line is beef.

Frequently Asked Questions

It makes numbers print with capital letters: hex digits A to F, the 0X prefix, and the E in scientific notation.
No. A string like "hello" is printed as it is. Use std::toupper to change letters in text.
Use std::hex and std::uppercase together: cout << hex << uppercase << 255.
Use std::nouppercase or cout.unsetf(std::ios::uppercase).
No. Decimal numbers have no letters, unless they are printed in scientific notation, where it changes the e.

Next: ws

Skip leading whitespace on an input stream.

ws tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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