Using stream classes
You can print floating point numbers and integers to the console using the cout
object (an instance of the ostream
class) or to files with an instance of ofstream
. Both of these classes will convert numbers to strings using member methods and manipulators to affect the formatting of the output string. Similarly, the cin
object (an instance of the istream
class) and the ifstream
class can read data from formatted streams.
Manipulators are functions that take a reference to a stream object and return that reference. The Standard Library has various global insertion operators whose parameters are a reference to a stream object and a function pointer. The appropriate insertion operator will call the function pointer with the stream object as its parameter. This means that the manipulator will have access to, and can manipulate, the stream it is inserted into. For input streams, there are also extraction operators that have a function parameter which will call the function...