13.3.2. Character Output Using Member Function put

We can use the put member function to output characters. For example, the statement

cout.put( 'A' );

displays a single character A. Calls to put may be cascaded, as in the statement

cout.put( 'A' ).put( '\n' );

which outputs the letter A followed by a newline character. As with <<, the preceding statement executes in this manner, because the dot operator (.) associates from left to right, and the put member function returns a reference to the ostream object (cout) that received the put call. The put function also may be called with a numeric expression that represents an ASCII value, as in the following statement, which also outputs A:

cout.put( 65 );

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.