Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

basic_ostream


basic_ostreambasic_iosios_base

Summary

Assists in formatting and writing output to sequences controlled by a stream buffer.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <ostream> 
template<class charT, class traits = char_traits<charT> >
class basic_ostream 
: virtual public basic_ios<charT, traits>

Description

The class basic_ostream defines member functions that assist in formatting and writing output to sequences controlled by a stream buffer.

Two groups of member functions share common properties: the formatted output functions (or insertors) and the unformatted output functions. Both groups of functions insert characters by calling basic_streambuf member functions. They both begin by constructing an object of class basic_ostream::sentry and, if this object is in good state after construction, the function tries to perform the requested output. The sentry object performs exception-safe initialization, such as controlling the status of the stream or locking it in a multithread environment.

Some formatted output functions generate the requested output by converting a value from some scalar to text form and inserting the converted text in the output sequence. The conversion behavior is directly depend on the locale object being imbued in the stream.

Interface

Types

char_type
int_type
ios_type
off_type
ostream
ostream_type
pos_type
traits_type
wostream

Constructors

explicit basic_ostream(basic_streambuf<charT, traits>* sb); 

Destructors

virtual ~basic_ostream();

Sentry Classes

explicit sentry(basic_ostream<charT,traits>&);
~sentry();
operator bool();

Insertors

ostream_type& 
operator<<(ostream_type& (*pf) (ostream_type&));
ostream_type& 
operator<<(ios_type& (*pf) (ios_type&));
ostream_type& 
operator<<(ios_base& (*pf) (ios_base&));
ostream_type& 
operator<<(bool n); 
ostream_type& 
operator<<(short n); 
ostream_type& 
operator<<(unsigned short n); 
ostream_type& 
operator<<(int n); 
ostream_type& 
operator<<(unsigned int n); 
ostream_type& 
operator<<(long n); 
ostream_type& 
operator<<(unsigned long n); 
ostream_type& 
operator<<(float f); 
ostream_type& 
operator<<(double f); 
ostream_type& 
operator<<(long double f); 
ostream_type& 
operator<<(void *p); 
ostream_type& 
operator<<(basic_streambuf<charT,traits> *sb); 
ostream_type& 
operator<<(basic_streambuf<charT,traits>& sb); 

Unformatted Functions

ostream_type& 
flush();
ostream_type& 
put(char_type c); 
ostream_type& 
seekp(pos_type pos); 
ostream_type& 
seekp(off_type off, ios_base::seekdir dir);
pos_type 
tellp();
ostream_type& 
write(const char_type* s, streamsize n); 

Non-member Functions

template<class charT, class traits>
basic_ostream<charT, traits>&
endl(basic_ostream<charT, traits>& os); 
template<class charT, class traits>
basic_ostream<charT, traits>&
ends(basic_ostream<charT, traits>& os); 
template<class charT, class traits>
basic_ostream<charT, traits>&
flush(basic_ostream<charT, traits>& os); 
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, charT c); 
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, char c);
template<class traits>
basic_ostream<char, traits>&
operator<<(basic_ostream<char, traits>& os, char c);
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, 
           const charT* s);
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, 
           const char* s);
template<class traits>
basic_ostream<char, traits>&
operator<<(basic_ostream<char, traits>& os, const char* s);
template<class traits>
basic_ostream<char, traits>&
operator<<(basic_ostream<char, traits>& os, 
           unsigned char c);
template<class traits>
basic_ostream<char, traits>&
operator<<(basic_ostream<char, traits>& os, signed char c);
template<class traits>
basic_ostream<char, traits>&
operator<<(basic_ostream<char, traits>& os, 
           unsigned char* c);
template<class traits>
basic_ostream<char, traits>&
operator<<(basic_ostream<char, traits>& os, 
           signed char* c);

Formatting

The formatting is done through member functions or manipulators.

Manipulators Member Functions
showpos
setf(ios_base::showpos)
noshowpos
unsetf(ios_base::showpos)
showbase
setf(ios_base::showbase)
noshowbase
unsetf(ios_base::showbase)
uppercase
setf(ios_base::uppercase)
nouppercase
unsetf(ios_base::uppercase)
showpoint
setf(ios_base::showpoint)
noshowpoint
unsetf(ios_base::showpoint)
boolalpha
setf(ios_base::boolalpha)
noboolalpha
unsetf(ios_base::boolalpha)
unitbuf
setf(ios_base::unitbuf)
nounitbuf
unsetf(ios_base::unitbuf)
internal
setf(ios_base::internal,
ios_base::adjustfield)
left
setf(ios_base::left,
ios_base::adjustfield)
right
setf(ios_base::right,
ios_base::adjustfield)
dec
setf(ios_base::dec,
ios_base::basefield)
hex
setf(ios_base::hex,
ios_base::basefield)
oct
setf(ios_base::oct,
ios_base::basefield)
fixed
setf(ios_base::fixed,
ios_base::floatfield)
scientific
setf(ios_base::scientific,
ios_base::floatfield)
resetiosflags
(ios_base::fmtflags flag)
setf(0,flag)
setiosflags
(ios_base::fmtflags flag)
setf(flag)
setbase(int base)
see above
setfill(char_type c)
fill(c)
setprecision(int n)
precision(n)
setw(int n)
width(n)

Description

showpos Generates a + sign in non-negative generated numeric output.
showbase Generates a prefix indicating the numeric base of generated integer output
uppercase Replaces certain lowercase letters with their uppercase equivalents in generated output
showpoint Generates a decimal-point character unconditionally in generated floating-point output
boolalpha Inserts and extracts bool type in alphabetic format
unitbuf Flushes output after each output operation
internal Adds fill characters at a designated internal point in certain generated output. If no such point is designated, it's identical to right.
left Adds fill characters on the right (final positions) of certain generated output
right Adds fill characters on the left (initial positions) of certain generated output
dec Converts integer input or generates integer output in decimal base
hex Converts integer input or generates integer output in hexadecimal base
oct Converts integer input or generates integer output in octal base
fixed Generates floating-point output in fixed-point notation
scientific Generates floating-point output in scientific notation
resetiosflags
(ios_base::fmtflags flag) Resets the fmtflags field flag
setiosflags
(ios_base::fmtflags flag) Sets up the flag flag
setbase(int base) Converts integer input or generates integer output in base base. The parameter base can be 8, 10 or 16.
setfill(char_type c) Sets the character used to pad (fill) an output conversion to the specified field width
setprecision(int n) Sets the precision (number of digits after the decimal point) to generate on certain output conversions
setw(int n) Sets the field with (number of characters) to generate on certain output conversions

Example

See Also

char_traits(3C++), ios_base(3C++), basic_ios(3C++), basic_streambuf(3C++), basic_iostream(3C++)

Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Section 27.6.2.1

Standards Conformance

ANSI X3J16/ISO WG21 Joint C++ Committee



Previous fileTop of documentContentsIndexNext file
Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998