0Pricing
C++ Academy · Lesson

Formatting Output with iomanip

Control width, precision, alignment, and number bases using the iomanip header.

The iomanip Header

The <iomanip> header provides manipulators — special objects you stream into cout to change its formatting state.

std::setw: Field Width

std::setw(n) sets the minimum width for the next field only. Shorter values are padded.

#include <iomanip>
std::cout << std::setw(10) << "Name" << std::setw(5) << "Age\n";
std::cout << std::setw(10) << "Ada"  << std::setw(5) << 36 << "\n";

All lessons in this course

  1. Using std::cin and std::cout Properly
  2. Formatting Output with iomanip
  3. Reading Input Safely with getline
  4. Working with std::cerr and std::clog
← Back to C++ Academy