The Other ostream
Methods
Besides the various operator<<()
functions, the ostream
class provides the put()
method for displaying characters and the write()
method for displaying strings.
Originally, the put()
method had the following prototype:
ostream & put(char);
The current standard is equivalent, except it’s templated to allow for wchar_t
. You invoke it by using the usual class method notation:
cout.put('W'); // display the W character
Here cout
is the invoking object and put()
is the class member function. Like the <<
operator functions, this function returns a reference to the invoking object, so you can concatenate output with it:
cout.put('I').put('t'); // displaying It with two put() calls
The function call cout.put('I')
returns ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.