Back to results for “I/O Streams”
C++ › I/O Streams

What are stream manipulators and how are they used?

Advanced

Answer

Manipulators are objects/functions that change stream formatting: std::endl (newline + flush), std::setw/std::setprecision/std::fixed (from <iomanip>), std::hex/std::dec, std::boolalpha, and std::flush. They're inserted into the stream to control width, precision, base, and formatting of subsequent output.
std::cout << std::fixed << std::setprecision(2) << 3.14159; // 3.14
Real-world example A report formats currency with std::fixed and setprecision(2) for consistent decimal places.

Common follow-ups: What does std::endl do besides newline? | Where do setw/setprecision come from?