C++ Iostream Functions and Manipulators

Beginner
10 min read
Updated: Nov 2026
60 guides
Function index

About This Index

This page is the C++ Iostream Functions index. Each row links to a full guide with syntax, parameters, return value, three examples, and FAQs. It covers stream member functions from <iostream>, <fstream>, and <sstream>, and manipulators from <ios> and <iomanip>.

Learn what streams are on /cpp/iostream. Use this page when you need one specific tool such as getline(), fail(), endl, or setw().

Two kinds of tools.

A member function is called with a dot, like std::cin.fail(). A manipulator goes inside a stream chain, like std::cout << std::hex. All 60 guides are listed below.

How to Use Iostream Functions

Include the headers you need. Call members with a dot and put manipulators into the stream:

C++
#include <iomanip>
#include <iostream>
#include <string>

int n;
std::string line;

std::cin >> n;                      // formatted input
if (std::cin.fail()) {               // member function
    std::cin.clear();                // reset the error flags
}
std::cin.ignore(1000, '\n');         // throw away the rest of the line
std::getline(std::cin, line);        // read a whole line

std::cout << std::setw(6) << n       // manipulator with argument
          << std::hex << 255          // manipulator: prints ff
          << std::endl;               // new line and flush

C++ Iostream Functions Table

All guides in this C++ tutorial series (60 tutorials), grouped by purpose.

Stream state

6 guides

Ask whether the last read or write worked, and reset the stream after a failure.

NameDescriptionTutorial
good()Check that no error or end-of-input flag is set.Try it
bad()Check for a serious, unrecoverable stream error.Try it
fail()Check whether the last read or write failed.Try it
eof()Check whether a read ran past the end of the input.Try it
clear()Reset the stream error flags so it can be used again.Try it
rdstate()Read all state flags of a stream at once.Try it

Characters, lines, and blocks

11 guides

Read and write single characters, whole lines, and raw blocks of text.

NameDescriptionTutorial
get()Read one character, spaces and new lines included.Try it
getline()Read a whole line of text, spaces included.Try it
put()Write one character to an output stream.Try it
write()Write a block of characters, with no formatting.Try it
read()Read a fixed number of characters into a buffer.Try it
readsome()Read only the characters that are ready right now.Try it
peek()Look at the next character without removing it.Try it
putback()Push a character back so it is read again.Try it
unget()Step back one character in the input stream.Try it
ignore()Skip and throw away characters from the input.Try it
gcount()Count how many characters the last read took.Try it

File and stream control

13 guides

Open and close files, flush output, move the read or write position, and set field width and flags.

NameDescriptionTutorial
open()Connect a file stream to a file on disk.Try it
close()Flush and disconnect a file stream from its file.Try it
is_open()Check whether a file stream is connected to a file.Try it
flush()Send buffered output to its destination now.Try it
sync()Synchronize the input buffer with its source.Try it
tie()Link an input stream to an output stream.Try it
seekg()Move the read position in an input stream.Try it
seekp()Move the write position in an output stream.Try it
tellg()Get the current read position of an input stream.Try it
tellp()Get the current write position of an output stream.Try it
width()Get or set the minimum width of the next output field.Try it
setf()Turn on one or more stream format flags.Try it
unsetf()Turn off one or more stream format flags.Try it

Format manipulators

21 guides

Put these into a stream with << or >> to change how numbers, bools, and spaces are handled. They come from <ios>, which iostream includes.

NameDescriptionTutorial
boolalphaPrint and read bool values as true and false.Try it
noboolalphaGo back to printing bool values as 1 and 0.Try it
showbasePrint a prefix such as 0x for hex and 0 for octal.Try it
noshowbaseStop printing the 0x and 0 base prefixes.Try it
showpointAlways print the decimal point and trailing zeros.Try it
noshowpointHide a needless decimal point and trailing zeros.Try it
showposPrint a plus sign in front of positive numbers.Try it
noshowposStop printing the plus sign for positive numbers.Try it
skipwsSkip leading spaces and new lines when reading.Try it
noskipwsRead spaces and new lines like normal characters.Try it
unitbufFlush the stream after every output operation.Try it
nounitbufStop flushing after every output operation.Try it
uppercaseUse capital letters in hex digits and exponents.Try it
nouppercaseGo back to small letters in hex digits and exponents.Try it
decRead and print integers in base 10.Try it
hexRead and print integers in base 16.Try it
octRead and print integers in base 8.Try it
fixedPrint floating-point numbers with a fixed number of decimals.Try it
scientificPrint floating-point numbers in scientific notation.Try it
leftAlign padded output to the left of its field.Try it
rightAlign padded output to the right of its field.Try it

iomanip and output helpers

8 guides

Manipulators that take a value (from <iomanip>) and the common line and flush helpers.

NameDescriptionTutorial
setw()Set the field width for the next item only.Try it
setfill()Choose the padding character used with setw.Try it
setprecision()Set how many digits a floating-point number shows.Try it
setbase()Set the number base to 8, 10, or 16.Try it
endlEnd the line and flush the output.Try it
endsWrite a null character to the output stream.Try it
flush()Send buffered output to its destination now.Try it
wsSkip leading whitespace on an input stream.Try it

C++23 print

2 guides

The newer formatted output functions from <print>. They need a C++23 compiler setting.

NameDescriptionTutorial
print()Print formatted text without a new line (C++23).Try it
println()Print formatted text followed by a new line (C++23).Try it

Frequently Asked Questions

They are the member functions of the stream classes (good, fail, get, getline, put, write, open, close, seekg, tellg and more) plus the manipulators you send into a stream, such as endl, hex, fixed, setw, and setprecision. Most need #include <iostream>; file functions need <fstream>, string streams need <sstream>, and setw-style manipulators need <iomanip>.
A member function is called with a dot on a stream, like std::cin.getline(buf, 20). A manipulator is placed inside a stream chain, like std::cout << std::hex << 255. Manipulators are really small helper functions that change the stream for you.
This series has 60 guides, grouped into stream state, characters and lines, file and stream control, format manipulators, iomanip helpers, and the C++23 print functions.
Include <iomanip>. Manipulators that take an argument live there. Manipulators without arguments, such as hex, fixed, and boolalpha, come with <iostream> (they are defined in <ios>).
Read the C++ iostream page first. Then open getline(), fail(), endl, and setw(). After that, the stream state functions and the format manipulators will feel easy.

Start with getline()

Read a whole line of text, spaces included. It is the first function most beginners need after cin.

getline() 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.

12 people found this page helpful