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( ' ' );
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 );