<ostream> <iostream>


for ostream
ostream& ends (ostream& os);
basic template
template <class charT, class traits>
basic_ostream<charT,traits>& ends (basic_ostream<charT,traits>& os);
Insert null character
Inserts a null character on os.

Its behavior is equivalent to calling os.put('\0') (or os.put(charT()) for other character types).


Output stream object where character is inserted.
Because this function is a manipulator, it is designed to be used alone with no arguments in conjunction with the insertion (<<) operations on output streams.

Return Value

Argument os.

Errors are signaled by modifying the internal state flags of os:
failbitMay be set if the construction of a sentry object failed.
badbitEither the insertion on the stream failed, or some other error happened (such as when this function catches an exception thrown by an internal operation).
When set, the integrity of the stream may have been affected.
Multiple flags may be set on os by a single operation.

If the operation sets an internal state flag of os that was registered using its member exceptions, the function throws an exception of type ios_base::failure.

Data races

Modifies os.
Concurrent access to the same stream object may cause data races, except for the standard stream objects (cout, cerr, clog, wcout, wcerr and wclog) when these are synchronized with stdio (in this case, no data races are initiated, although no guarantees are given on the order in which characters from multiple threads are inserted).

Exception safety

Basic guarantee: if an exception is thrown, os is in a valid state.
It throws an exception of member type failure if the resulting error state flag of os is not goodbit and member exceptions was set to throw for that state.
Any exception thrown by an internal operation is caught and handled by the function, setting os's badbit. If badbit was set on the last call to exceptions for os, the function rethrows the caught exception.

See also