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
- Using std::cin and std::cout Properly
- Formatting Output with iomanip
- Reading Input Safely with getline
- Working with std::cerr and std::clog