You are on page 1of 3

std::ios_base

Dened in header <ios>

class ios_base;
The clas s ios_baseis a multipurpos e clas s that s erves as the bas e clas s for all I/O s tream clas s es . It
maintains s everal kinds of data:
1) s tate information: s tream s tatus ags
2) control information: ags that control formatting of both input and output s equences and the
imbued locale
3) private s torage: indexed extens ible data s tructure that allows both long and void* members ,
which may be implemented as two arbitrary-length arrays or a s ingle array of two-element s tructs
or another container.
4) callbacks : arbitrary number of us er-dened functions to be called from imbue(), copyfmt(), and
~ios _bas e()
Typical implementation holds member cons tants corres ponding to all values of fmtags , ios tate,
openmode, and s eekdir s hown below, member variables to maintain current precis ion, width, and
formatting ags , the exception mas k, the buer error s tate, a res izeable container holding the callbacks ,
the currently imbued locale, the private s torage, and a s tatic integer variable for xalloc().

Member functions
(cons tructor)
(des tructor) [virtual]

cons tructs the object


(protec ted member func tion)

des tructs the object


(virtual public member func tion)

Formatting

flags
setf
unsetf
precision
width

manages format ags


(public member func tion)

s ets s pecic format ag


(public member func tion)

clears s pecic format ag


(public member func tion)

manages decimal precis ion of oating point operations


(public member func tion)

manages eld width


(public member func tion)

Locales

imbue
getloc

s ets locale
(public member func tion)

returns current locale


(public member func tion)

Internal extensible array

xalloc[static ]

returns a program-wide unique integer that is s afe to us e as index to pword()


and iword()
(public static member func tion)

iword

res izes the private s torage if neces s ary and acces s to the long element at
the given index
(public member func tion)

pword

res izes the private s torage if neces s ary and acces s to the void* element
at the given index
(public member func tion)

Miscellaneous

register_callback

regis ters event callback function


(public member func tion)

s ets whether C++ and C IO libraries are interoperable

sync_with_stdio[static ] s ets whether C++ and C IO libraries are interoperable


(public static member func tion)

Member classes
s tream exception

failure

(public member c lass)

initializes s tandard s tream objects

Init

(public member c lass)

Member types and constants


Type

Explanation
s tream open mode type
The following cons tants are als o dened:
Constant Explanation

openmode

app

s eek to the end of s tream before each write

binary

open in binary mode

in

open for reading

out

open for writing

trunc

dis card the contents of the s tream when opening

ate

s eek to the end of s tream immediately after open

(typedef)

formatting ags type


The following cons tants are als o dened:
Constant

Explanation

dec

us e decimal bas e for integer I/O: s ee std::dec

oct

us e octal bas e for integer I/O: s ee std::oct

hex

us e hexadecimal bas e for integer I/O: s ee std::hex

basefield

fmtflags

dec|oct|hex|0. Us eful for mas king operations

left

left adjus tment (adds ll characters to the right): s ee std::left

right

right adjus tment (adds ll characters to the left): s ee std::right

internal

internal adjus tment (adds ll characters to the internal des ignated


point): s ee std::internal

adjustfield left|right|internal. Us eful for mas king operations


generate oating point types us ing s cientic notation, or hex
scientific
notation if combined with xed: s ee std::scientific
generate oating point types us ing xed notation, or hex notation if
fixed
combined with s cientic: s ee std::fixed
floatfield
boolalpha
showbase
showpoint
showpos
skipws
unitbuf
uppercase

scientific|fixed|(scientific|fixed)|0. Us eful for mas king


operations
ins ert and extract bool type in alphanumeric format: s ee
std::boolalpha
generate a prex indicating the numeric bas e for integer output,
require the currency indicator in monetary I/O: s ee std::showbase
generate a decimal-point character unconditionally for oating-point
number output: s ee std::showpoint
generate a + character for non-negative numeric output: s ee
std::showpos
s kip leading whites pace before certain input operations : s ee
std::skipws
us h the output after each output operation: s ee std::unitbuf
replace certain lowercas e letters with their uppercas e
equivalents in certain output output operations : s ee
std::uppercase

(typedef)

s tate of the s tream type


The following cons tants are als o dened:

Constant Explanation
iostate

goodbit

no error

badbit

irrecoverable s tream error

failbit

input/output operation failed (formatting or extraction error)

eofbit

as s ociated input s equence has reached end-of-le

(typedef)

s eeking direction type


The following cons tants are als o dened:
Constant Explanation
seekdir

beg

the beginning of a s tream

end

the ending of a s tream

cur

the current pos ition of s tream pos ition indicator

(typedef)

event

s pecies event type


(enum)

callback function type


event_callback (typedef)
Deprecated member types

Type

Explanation

io_state(deprec ated)

integer type that may be us ed like iostate

open_mode(deprec ated) integer type that may be us ed like openmode


seek_dir(deprec ated)

integer type that may be us ed like seekdir

uns pecied type that may be us ed like off_type, not neces s arily
std::streamoff
uns pecied type that may be us ed like pos_type, not neces s arily
streampos(deprec ated)
std::streampos
streamoff(deprec ated)

Retrieved from "http://en.c ppreferenc e.c om/mwiki/index.php?title=c pp/io/ios_base& oldid=81364"

(until C++17)

You might also like