Standard library header <ios> - cppreference.com

From cppreference.com

This header is part of the

Input/Output

library.

Includes

<iosfwd>

Forward declarations of all classes in the input/output library

[edit]

Classes

ios_base

manages formatting flags and input/output exceptions
(class)

[edit]

basic_ios

manages an arbitrary stream buffer
(class template)

[edit]

std::ios

std::basic_ios<char>(typedef)

std::wios

std::basic_ios<wchar_t>(typedef)

fpos

represents absolute position in a stream or a file
(class template)

[edit]

io_errc

(C++11)

the IO stream error codes
(enum)

[edit]

is_error_code_enum<std::io_errc>

(C++11)

extends the type trait

std::is_error_code_enum

to identify iostream error codes
(class template specialization)

[edit]

streamoff

represents relative file/stream position (offset from fpos), sufficient to represent any file size
(typedef)

[edit]

streamsize

represents the number of characters transferred in an I/O operation or the size of an I/O buffer
(typedef)

[edit]

Functions

iostream_category

(C++11)

identifies the iostream error category
(function)

[edit]

make_error_code(std::io_errc)

(C++11)

constructs an iostream error code
(function)

[edit]

make_error_condition(std::io_errc)

(C++11)

constructs an iostream error condition
(function)

[edit]

boolalphanoboolalpha

switches between textual and numeric representation of booleans
(function)

[edit]

showbasenoshowbase

controls whether prefix is used to indicate numeric base
(function)

[edit]

showpointnoshowpoint

controls whether decimal point is always included in floating-point representation
(function)

[edit]

showposnoshowpos

controls whether the + sign used with non-negative numbers
(function)

[edit]

skipwsnoskipws

controls whether leading whitespace is skipped on input
(function)

[edit]

uppercasenouppercase

controls whether uppercase characters are used with some output formats
(function)

[edit]

unitbufnounitbuf

controls whether output is flushed after each operation
(function)

[edit]

internalleftright

sets the placement of fill characters
(function)

[edit]

dechexoct

changes the base used for integer I/O
(function)

[edit]

fixedscientifichexfloatdefaultfloat

(C++11)(C++11)

changes formatting used for floating-point I/O
(function)

[edit]

Synopsis

#include<iosfwd>namespacestd{usingstreamoff=/* implementation-defined */;usingstreamsize=/* implementation-defined */;template<classStateT>classfpos;classios_base;template<classCharT,classTraits=char_traits<CharT>>classbasic_ios;// manipulatorsios_base&boolalpha(ios_base&str);ios_base&noboolalpha(ios_base&str);ios_base&showbase(ios_base&str);ios_base&noshowbase(ios_base&str);ios_base&showpoint(ios_base&str);ios_base&noshowpoint(ios_base&str);ios_base&showpos(ios_base&str);ios_base&noshowpos(ios_base&str);ios_base&skipws(ios_base&str);ios_base&noskipws(ios_base&str);ios_base&uppercase(ios_base&str);ios_base&nouppercase(ios_base&str);ios_base&unitbuf(ios_base&str);ios_base&nounitbuf(ios_base&str);// adjustfieldios_base&internal(ios_base&str);ios_base&left(ios_base&str);ios_base&right(ios_base&str);// basefieldios_base&dec(ios_base&str);ios_base&hex(ios_base&str);ios_base&oct(ios_base&str);// floatfieldios_base&fixed(ios_base&str);ios_base&scientific(ios_base&str);ios_base&hexfloat(ios_base&str);ios_base&defaultfloat(ios_base&str);// error reportingenumclassio_errc{stream=1};template<>structis_error_code_enum<io_errc>:publictrue_type{};error_codemake_error_code(io_errce)noexcept;error_conditionmake_error_condition(io_errce)noexcept;consterror_category&iostream_category()noexcept;}Class

std::ios_base

namespacestd{classios_base{public:classfailure;// see description// fmtflagsusingfmtflags=/*bitmask-type-1*/;staticconstexprfmtflagsboolalpha=/* unspecified */;staticconstexprfmtflagsdec=/* unspecified */;staticconstexprfmtflagsfixed=/* unspecified */;staticconstexprfmtflagshex=/* unspecified */;staticconstexprfmtflagsinternal=/* unspecified */;staticconstexprfmtflagsleft=/* unspecified */;staticconstexprfmtflagsoct=/* unspecified */;staticconstexprfmtflagsright=/* unspecified */;staticconstexprfmtflagsscientific=/* unspecified */;staticconstexprfmtflagsshowbase=/* unspecified */;staticconstexprfmtflagsshowpoint=/* unspecified */;staticconstexprfmtflagsshowpos=/* unspecified */;staticconstexprfmtflagsskipws=/* unspecified */;staticconstexprfmtflagsunitbuf=/* unspecified */;staticconstexprfmtflagsuppercase=/* unspecified */;staticconstexprfmtflagsadjustfield=/* see description */;staticconstexprfmtflagsbasefield=/* see description */;staticconstexprfmtflagsfloatfield=/* see description */;// iostateusingiostate=/*bitmask-type-2*/;staticconstexpriostatebadbit=/* unspecified */;staticconstexpriostateeofbit=/* unspecified */;staticconstexpriostatefailbit=/* unspecified */;staticconstexpriostategoodbit=/* see description */;// openmodeusingopenmode=/*bitmask-type-3*/;staticconstexpropenmodeapp=/* unspecified */;staticconstexpropenmodeate=/* unspecified */;staticconstexpropenmodebinary=/* unspecified */;staticconstexpropenmodein=/* unspecified */;staticconstexpropenmodeout=/* unspecified */;staticconstexpropenmodetrunc=/* unspecified */;staticconstexpropenmodenoreplace=/* unspecified */// seekdirusingseekdir=/*bitmask-type-4*/;staticconstexprseekdirbeg=/* unspecified */;staticconstexprseekdircur=/* unspecified */;staticconstexprseekdirend=/* unspecified */;classInit;// fmtflags statefmtflagsflags()const;fmtflagsflags(fmtflagsfmtfl);fmtflagssetf(fmtflagsfmtfl);fmtflagssetf(fmtflagsfmtfl,fmtflagsmask);voidunsetf(fmtflagsmask);streamsizeprecision()const;streamsizeprecision(streamsizeprec);streamsizewidth()const;streamsizewidth(streamsizewide);// localeslocaleimbue(constlocale&loc);localegetloc()const;// storagestaticintxalloc();long&iword(intidx);void*&pword(intidx);// destructorvirtual~ios_base();// callbacksenumevent{erase_event,imbue_event,copyfmt_event};usingevent_callback=void(*)(event,ios_base&,intidx);voidregister_callback(event_callbackfn,intidx);ios_base(constios_base&)=delete;ios_base&operator=(constios_base&)=delete;staticboolsync_with_stdio(boolsync=true);protected:ios_base();private:staticintindex;// exposition onlylong*iarray;// exposition onlyvoid**parray;// exposition only};}Class

std::ios_base::failure

namespacestd{classios_base::failure:publicsystem_error{public:explicitfailure(conststring&msg,consterror_code&ec=io_errc::stream);explicitfailure(constchar*msg,consterror_code&ec=io_errc::stream);};}Class

std::ios_base::Init

namespacestd{classios_base::Init{public:Init();Init(constInit&)=default;~Init();Init&operator=(constInit&)=default;private:staticintinit_cnt;// exposition only};}Class template

std::fpos

namespacestd{template<classStateT>classfpos{public:// membersStateTstate()const;voidstate(stateT);private;StateTst;// exposition only};}Class template

std::basic_ios

namespacestd{template<classCharT,classTraits=char_traits<CharT>>classbasic_ios:publicios_base{public:usingchar_type=CharT;usingint_type=typenameTraits::int_type;usingpos_type=typenameTraits::pos_type;usingoff_type=typenameTraits::off_type;usingtraits_type=Traits;// flags functionsexplicitoperatorbool()const;booloperator!()const;iostaterdstate()const;voidclear(iostatestate=goodbit);voidsetstate(iostatestate);boolgood()const;booleof()const;boolfail()const;boolbad()const;iostateexceptions()const;voidexceptions(iostateexcept);// constructor/destructorexplicitbasic_ios(basic_streambuf<CharT,Traits>*sb);virtual~basic_ios();// membersbasic_ostream<CharT,Traits>*tie()const;basic_ostream<CharT,Traits>*tie(basic_ostream<CharT,Traits>*tiestr);basic_streambuf<CharT,Traits>*rdbuf()const;basic_streambuf<CharT,Traits>*rdbuf(basic_streambuf<CharT,Traits>*sb);basic_ios&copyfmt(constbasic_ios&rhs);char_typefill()const;char_typefill(char_typech);localeimbue(constlocale&loc);charnarrow(char_typec,chardfault)const;char_typewiden(charc)const;basic_ios(constbasic_ios&)=delete;basic_ios&operator=(constbasic_ios&)=delete;protected:basic_ios();voidinit(basic_streambuf<CharT,Traits>*sb);voidmove(basic_ios&rhs);voidmove(basic_ios&&rhs);voidswap(basic_ios&rhs)noexcept;voidset_rdbuf(basic_streambuf<CharT,Traits>*sb);};}Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior

LWG 35

C++98 the prototypes of unitbuf and nounitbuf were missing in the synopsis added

LWG 78

C++98 the type of parameter fn of

ios_base::register_callback

in the synopsis was misspecified as event_call_backcorrected to
event_callback