Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

cout

Library:  Input/output

Local Index

No Entries

Summary

Predefined stream that controls output to a stream buffer associated with the object stdout declared in <cstdio>

Synopsis

#include <iostream>

namespace std {
  extern ostream cout;
}

Description

The object cout controls output to a stream buffer associated with the object stdout declared in <cstdio>. By default the standard C and C++ streams are synchronized, but performance improvement can be achieved by using the ios_base member function synch_with_stdio to desynchronize them.

After the object cin is initialized, cin.tie() returns &cout, which implies that cin and cout are synchronized.

Formatting

The formatting is done through member functions or manipulators.

Table 16: Formatting functions and manipulators for cout

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)

endl

 

ends

 

flush

flush( )

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 width (number of characters) to generate on certain output conversions

endl

Inserts a newline character into the output sequence and flushes the output buffer

ends

Inserts a null character into the output sequence

flush

Flushes the output buffer

Default Values

Warnings

Keep in mind that while the manipulator endl flushes the stream buffer, outputting the character '\n' is not guaranteed to flush the stream buffer. You should output the '\n' character without endl only if you do not need the buffer flushed. Note that outputting the '\n' character in such cases, and hence not forcing a buffer flush, may result in a performance improvement. It greatly improves performance when C and C++ streams are not synchronized.

See Also

basic_ostream, basic_iostream, basic_filebuf, cin, cerr, clog, wcin, wcout, wcerr, wclog

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Section 27.3.1



Previous fileTop of DocumentContentsIndex pageNext file