Input and Output

Strings are well-known for their use in input and output of data. Let's look at how this is done.

A string can read from an input stream via >> and write to an output stream via <<.

The global function getline empowers us to read from an input stream line by line until the end-of-file character.

There are four variations of the getline function available. The first two arguments are the input stream is and the string line holding the line read. Optionally we can specify a special line separator. The function returns by reference to the input stream.

Get hands-on with 1400+ tech skills courses.