In practice, you'll usually want to get your input a line at a time as a sequence of characters and then scan them and perform conversions once they're safely in a buffer. This way you don't have to worry about the input routine choking on unexpected data. Another thing to consider is the whole concept of a command-line interface . Read the input without attempting to convert it. Once the input is someplace where it can't foul things up during conversion, then you can safely scan it.
Output is different.
Otherwise it often makes sense to send it to cout . In both cases, the output formatting functions of iostreams are highly useful. Both functions store a zero in the result buffer when they encounter the terminating character in the input. That is explored later in the chapter. The first argument is a pointer to the destination memory, and the second is the number of bytes to read.