Redirecting Streams in C++

In C++, input and output are performed using streams, which are sequences of bytes, Common stream objects are cin (which reads input from the keyboard), and cout (which displays output on the screen).

Each stream has a buffer, which temporarily stores data to make input/output faster.

I/O redirection means changing where the program gets input from or sends output to. For example, sending cout output to a file instead of the screen.


The function ios::rdbuf() is used to redirect streams to different sources or destinations.