In this section, we are going to learn about the basics and some advantages and disadvantages of stream-based IO.
Learning about stream-based IO
The basics of stream
Unlike the C-style printf() and scanf() functions, C++ IO uses streams (std::ostream for output and std::istream for input) that leverage the << and >> operators. For example, the following code outputs Hello World to stdout using a non-member << overload of basic_ostream for const char * strings:
#include <iostream>
int main()
{
std::cout << "Hello World\n";
}
> g++ -std=c++17 scratchpad.cpp; ./a.out
Hello World
By default, the std::cout and std::wcout objects, which are instantiations of std::ostream, output data to the...