735 lines
31 KiB
Markdown
735 lines
31 KiB
Markdown
[ios.base]
|
||
|
||
# 31 Input/output library [[input.output]](./#input.output)
|
||
|
||
## 31.5 Iostreams base classes [[iostreams.base]](iostreams.base#ios.base)
|
||
|
||
### 31.5.2 Class ios_base [ios.base]
|
||
|
||
#### [31.5.2.1](#general) General [[ios.base.general]](ios.base.general)
|
||
|
||
[ð](#lib:ios_base)
|
||
|
||
namespace std {class ios_base {public:class failure; // see below// [[ios.fmtflags]](#ios.fmtflags "31.5.2.2.2 Type ios_base::fmtflags"), fmtflagsusing fmtflags = *T1*; static constexpr fmtflags boolalpha = *unspecified*; static constexpr fmtflags dec = *unspecified*; static constexpr fmtflags fixed = *unspecified*; static constexpr fmtflags hex = *unspecified*; static constexpr fmtflags internal = *unspecified*; static constexpr fmtflags left = *unspecified*; static constexpr fmtflags oct = *unspecified*; static constexpr fmtflags right = *unspecified*; static constexpr fmtflags scientific = *unspecified*; static constexpr fmtflags showbase = *unspecified*; static constexpr fmtflags showpoint = *unspecified*; static constexpr fmtflags showpos = *unspecified*; static constexpr fmtflags skipws = *unspecified*; static constexpr fmtflags unitbuf = *unspecified*; static constexpr fmtflags uppercase = *unspecified*; static constexpr fmtflags adjustfield = *see below*; static constexpr fmtflags basefield = *see below*; static constexpr fmtflags floatfield = *see below*; // [[ios.iostate]](#ios.iostate "31.5.2.2.3 Type ios_base::iostate"), iostateusing iostate = *T2*; static constexpr iostate badbit = *unspecified*; static constexpr iostate eofbit = *unspecified*; static constexpr iostate failbit = *unspecified*; static constexpr iostate goodbit = *see below*; // [[ios.openmode]](#ios.openmode "31.5.2.2.4 Type ios_base::openmode"), openmodeusing openmode = *T3*; static constexpr openmode app = *unspecified*; static constexpr openmode ate = *unspecified*; static constexpr openmode binary = *unspecified*; static constexpr openmode in = *unspecified*; static constexpr openmode noreplace = *unspecified*; static constexpr openmode out = *unspecified*; static constexpr openmode trunc = *unspecified*; // [[ios.seekdir]](#ios.seekdir "31.5.2.2.5 Type ios_base::seekdir"), seekdirusing seekdir = *T4*; static constexpr seekdir beg = *unspecified*; static constexpr seekdir cur = *unspecified*; static constexpr seekdir end = *unspecified*; class Init; // [[fmtflags.state]](#fmtflags.state "31.5.2.3 State functions"), fmtflags state fmtflags flags() const;
|
||
fmtflags flags(fmtflags fmtfl);
|
||
fmtflags setf(fmtflags fmtfl);
|
||
fmtflags setf(fmtflags fmtfl, fmtflags mask); void unsetf(fmtflags mask);
|
||
|
||
streamsize precision() const;
|
||
streamsize precision(streamsize prec);
|
||
streamsize width() const;
|
||
streamsize width(streamsize wide); // [[ios.base.locales]](#locales "31.5.2.4 Functions"), locales locale imbue(const locale& loc);
|
||
locale getloc() const; // [[ios.base.storage]](#storage "31.5.2.6 Storage functions"), storagestatic int xalloc(); long& iword(int idx); void*& pword(int idx); // destructorvirtual ~ios_base(); // [[ios.base.callback]](#callback "31.5.2.7 Callbacks"), callbacksenum [event](#lib:ios_base,event "31.5.2.1 General [ios.base.general]") { erase_event, imbue_event, copyfmt_event }; using event_callback = void (*)(event, ios_base&, int idx); void register_callback(event_callback fn, int idx);
|
||
|
||
ios_base(const ios_base&) = delete;
|
||
ios_base& operator=(const ios_base&) = delete; static bool sync_with_stdio(bool sync = true); protected: ios_base(); private:static int *index*; // *exposition only*long* *iarray*; // *exposition only*void** *parray*; // *exposition only*};}
|
||
|
||
[1](#general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L854)
|
||
|
||
ios_base defines several member types:
|
||
|
||
- [(1.1)](#general-1.1)
|
||
|
||
a type failure, defined as either a class derived fromsystem_error or a synonym for a class derived from system_error;
|
||
|
||
- [(1.2)](#general-1.2)
|
||
|
||
a class Init;
|
||
|
||
- [(1.3)](#general-1.3)
|
||
|
||
three bitmask types, fmtflags, iostate, and openmode;
|
||
|
||
- [(1.4)](#general-1.4)
|
||
|
||
an enumerated type, seekdir[.](#general-1.sentence-1)
|
||
|
||
[2](#general-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L868)
|
||
|
||
It maintains several kinds of data:
|
||
|
||
- [(2.1)](#general-2.1)
|
||
|
||
state information that reflects the integrity of the stream buffer;
|
||
|
||
- [(2.2)](#general-2.2)
|
||
|
||
control information that influences how to interpret (format) input
|
||
sequences and how to generate (format) output sequences;
|
||
|
||
- [(2.3)](#general-2.3)
|
||
|
||
additional information that is stored by the program for its private use[.](#general-2.sentence-1)
|
||
|
||
[3](#general-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L880)
|
||
|
||
[*Note [1](#general-note-1)*:
|
||
|
||
For the sake of exposition, the maintained data is presented here as:
|
||
|
||
- [(3.1)](#general-3.1)
|
||
|
||
static int *index*,
|
||
specifies the next available
|
||
unique index for the integer or pointer arrays maintained for the private use
|
||
of the program, initialized to an unspecified value;
|
||
|
||
- [(3.2)](#general-3.2)
|
||
|
||
long* *iarray*,
|
||
points to the first element of an
|
||
arbitrary-lengthlong array maintained for the private use of the
|
||
program;
|
||
|
||
- [(3.3)](#general-3.3)
|
||
|
||
void** *parray*,
|
||
points to the first element of an
|
||
arbitrary-length pointer array maintained for the private use of the program[.](#general-3.sentence-1)
|
||
|
||
â *end note*]
|
||
|
||
#### [31.5.2.2](#ios.types) Types [[ios.types]](ios.types)
|
||
|
||
#### [31.5.2.2.1](#ios.failure) Class ios_base::failure [[ios.failure]](ios.failure)
|
||
|
||
[ð](#lib:ios_base::failure)
|
||
|
||
namespace std {class ios_base::failure : public system_error {public:explicit failure(const string& msg, const error_code& ec = io_errc::stream); explicit failure(const char* msg, const error_code& ec = io_errc::stream); };}
|
||
|
||
[1](#ios.failure-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L919)
|
||
|
||
An implementation is permitted to define ios_base::failure as a synonym for a class with equivalent functionality
|
||
to class ios_base::failure shown in this subclause[.](#ios.failure-1.sentence-1)
|
||
|
||
[*Note [1](#ios.failure-note-1)*:
|
||
|
||
When ios_base::failure is a synonym for another type,
|
||
that type needs to provide a nested type failure to emulate the injected-class-name[.](#ios.failure-1.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
The classfailure defines the base class
|
||
for the types of all objects thrown as exceptions,
|
||
by functions in the iostreams library,
|
||
to report errors detected during stream buffer operations[.](#ios.failure-1.sentence-3)
|
||
|
||
[2](#ios.failure-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L935)
|
||
|
||
When throwing ios_base::failure exceptions, implementations should provide
|
||
values of ec that identify the specific reason for the failure[.](#ios.failure-2.sentence-1)
|
||
|
||
[*Note [2](#ios.failure-note-2)*:
|
||
|
||
Errors arising from the operating system would typically be reported assystem_category() errors with an error value of the error number
|
||
reported by the operating system[.](#ios.failure-2.sentence-2)
|
||
|
||
Errors arising from within the stream library would
|
||
typically be reported as error_code(io_errc::stream,
|
||
iostream_category())[.](#ios.failure-2.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#lib:ios_base::failure,constructor)
|
||
|
||
`explicit failure(const string& msg, const error_code& ec = io_errc::stream);
|
||
`
|
||
|
||
[3](#ios.failure-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L952)
|
||
|
||
*Effects*: Constructs the base class with msg and ec[.](#ios.failure-3.sentence-1)
|
||
|
||
[ð](#lib:ios_base::failure,constructor_)
|
||
|
||
`explicit failure(const char* msg, const error_code& ec = io_errc::stream);
|
||
`
|
||
|
||
[4](#ios.failure-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L963)
|
||
|
||
*Effects*: Constructs the base class with msg and ec[.](#ios.failure-4.sentence-1)
|
||
|
||
#### [31.5.2.2.2](#ios.fmtflags) Type ios_base::fmtflags [[ios.fmtflags]](ios.fmtflags)
|
||
|
||
[ð](#lib:fmtflags,ios_base)
|
||
|
||
`using fmtflags = T1;
|
||
`
|
||
|
||
[1](#ios.fmtflags-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L976)
|
||
|
||
The typefmtflags is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))[.](#ios.fmtflags-1.sentence-1)
|
||
|
||
Setting its elements has the effects indicated in Table [136](#tab:ios.fmtflags "Table 136: fmtflags effects")[.](#ios.fmtflags-1.sentence-2)
|
||
|
||
Table [136](#tab:ios.fmtflags) — fmtflags effects [[tab:ios.fmtflags]](./tab:ios.fmtflags)
|
||
|
||
| [ð](#tab:ios.fmtflags-row-1)<br>**Element** | **Effect(s) if set** |
|
||
| --- | --- |
|
||
| [ð](#tab:ios.fmtflags-row-2)<br>boolalpha | insert and extract bool type in alphabetic format |
|
||
| [ð](#tab:ios.fmtflags-row-3)<br>dec | converts integer input or generates integer output in decimal base |
|
||
| [ð](#tab:ios.fmtflags-row-4)<br>fixed | generate floating-point output in fixed-point notation |
|
||
| [ð](#tab:ios.fmtflags-row-5)<br>hex | converts integer input or generates integer output in hexadecimal base |
|
||
| [ð](#tab:ios.fmtflags-row-6)<br>internal | adds fill characters at a designated internal point in certain generated output, or identical to right if no such point is designated |
|
||
| [ð](#tab:ios.fmtflags-row-7)<br>left | adds fill characters on the right (final positions) of certain generated output |
|
||
| [ð](#tab:ios.fmtflags-row-8)<br>oct | converts integer input or generates integer output in octal base |
|
||
| [ð](#tab:ios.fmtflags-row-9)<br>right | adds fill characters on the left (initial positions) of certain generated output |
|
||
| [ð](#tab:ios.fmtflags-row-10)<br>scientific | generates floating-point output in scientific notation |
|
||
| [ð](#tab:ios.fmtflags-row-11)<br>showbase | generates a prefix indicating the numeric base of generated integer output |
|
||
| [ð](#tab:ios.fmtflags-row-12)<br>showpoint | generates a decimal-point character unconditionally in generated floating-point output |
|
||
| [ð](#tab:ios.fmtflags-row-13)<br>showpos | generates a + sign in non-negative generated numeric output |
|
||
| [ð](#tab:ios.fmtflags-row-14)<br>skipws | skips leading whitespace before certain input operations |
|
||
| [ð](#tab:ios.fmtflags-row-15)<br>unitbuf | flushes output after each output operation |
|
||
| [ð](#tab:ios.fmtflags-row-16)<br>uppercase | replaces certain lowercase letters with their uppercase equivalents in generated output |
|
||
|
||
[2](#ios.fmtflags-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1016)
|
||
|
||
Typefmtflags also defines the constants indicated in Table [137](#tab:ios.fmtflags.const "Table 137: fmtflags constants")[.](#ios.fmtflags-2.sentence-1)
|
||
|
||
Table [137](#tab:ios.fmtflags.const) — fmtflags constants [[tab:ios.fmtflags.const]](./tab:ios.fmtflags.const)
|
||
|
||
| [ð](#tab:ios.fmtflags.const-row-1)<br>**Constant** | **Allowable values** |
|
||
| --- | --- |
|
||
| [ð](#tab:ios.fmtflags.const-row-2)<br>adjustfield | left | right | internal |
|
||
| [ð](#tab:ios.fmtflags.const-row-3)<br>basefield | dec | oct | hex |
|
||
| [ð](#tab:ios.fmtflags.const-row-4)<br>floatfield | scientific | fixed |
|
||
|
||
#### [31.5.2.2.3](#ios.iostate) Type ios_base::iostate [[ios.iostate]](ios.iostate)
|
||
|
||
[ð](#lib:iostate,ios_base)
|
||
|
||
`using iostate = T2;
|
||
`
|
||
|
||
[1](#ios.iostate-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1039)
|
||
|
||
The typeiostate is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))
|
||
that contains the elements indicated in Table [138](#tab:ios.iostate "Table 138: iostate effects")[.](#ios.iostate-1.sentence-1)
|
||
|
||
Table [138](#tab:ios.iostate) — iostate effects [[tab:ios.iostate]](./tab:ios.iostate)
|
||
|
||
| [ð](#tab:ios.iostate-row-1)<br>**Element** | **Effect(s) if set** |
|
||
| --- | --- |
|
||
| [ð](#tab:ios.iostate-row-2)<br>badbit | indicates a loss of integrity in an input or output sequence (such as an irrecoverable read error from a file); |
|
||
| [ð](#tab:ios.iostate-row-3)<br>eofbit | indicates that an input operation reached the end of an input sequence; |
|
||
| [ð](#tab:ios.iostate-row-4)<br>failbit | indicates that an input operation failed to read the expected characters, or that an output operation failed to generate the desired characters[.](#tab:ios.iostate-row-4-column-2-sentence-1) |
|
||
|
||
[2](#ios.iostate-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1056)
|
||
|
||
Typeiostate also defines the constant:
|
||
|
||
- [(2.1)](#ios.iostate-2.1)
|
||
|
||
goodbit,
|
||
the value zero[.](#ios.iostate-2.sentence-1)
|
||
|
||
#### [31.5.2.2.4](#ios.openmode) Type ios_base::openmode [[ios.openmode]](ios.openmode)
|
||
|
||
[ð](#lib:openmode,ios_base)
|
||
|
||
`using openmode = T3;
|
||
`
|
||
|
||
[1](#ios.openmode-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1075)
|
||
|
||
The typeopenmode is a bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))[.](#ios.openmode-1.sentence-1)
|
||
|
||
It contains the elements indicated in Table [139](#tab:ios.openmode "Table 139: openmode effects")[.](#ios.openmode-1.sentence-2)
|
||
|
||
Table [139](#tab:ios.openmode) — openmode effects [[tab:ios.openmode]](./tab:ios.openmode)
|
||
|
||
| [ð](#tab:ios.openmode-row-1)<br>**Element** | **Effect(s) if set** |
|
||
| --- | --- |
|
||
| [ð](#tab:ios.openmode-row-2)<br>app | seek to end before each write |
|
||
| [ð](#tab:ios.openmode-row-3)<br>ate | open and seek to end immediately after opening |
|
||
| [ð](#tab:ios.openmode-row-4)<br>binary | perform input and output in binary mode (as opposed to text mode) |
|
||
| [ð](#tab:ios.openmode-row-5)<br>in | open for input |
|
||
| [ð](#tab:ios.openmode-row-6)<br>noreplace | open in exclusive mode |
|
||
| [ð](#tab:ios.openmode-row-7)<br>out | open for output |
|
||
| [ð](#tab:ios.openmode-row-8)<br>trunc | truncate an existing stream when opening |
|
||
|
||
#### [31.5.2.2.5](#ios.seekdir) Type ios_base::seekdir [[ios.seekdir]](ios.seekdir)
|
||
|
||
[ð](#lib:seekdir,ios_base)
|
||
|
||
`using seekdir = T4;
|
||
`
|
||
|
||
[1](#ios.seekdir-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1107)
|
||
|
||
The typeseekdir is an enumerated type ([[enumerated.types]](enumerated.types "16.3.3.3.2 Enumerated types"))
|
||
that contains the elements indicated in Table [140](#tab:ios.seekdir "Table 140: seekdir effects")[.](#ios.seekdir-1.sentence-1)
|
||
|
||
Table [140](#tab:ios.seekdir) — seekdir effects [[tab:ios.seekdir]](./tab:ios.seekdir)
|
||
|
||
| [ð](#tab:ios.seekdir-row-1)<br>**Element** | **Meaning** |
|
||
| --- | --- |
|
||
| [ð](#tab:ios.seekdir-row-2)<br>beg | request a seek (for subsequent input or output) relative to the beginning of the stream |
|
||
| [ð](#tab:ios.seekdir-row-3)<br>cur | request a seek relative to the current position within the sequence |
|
||
| [ð](#tab:ios.seekdir-row-4)<br>end | request a seek relative to the current end of the sequence |
|
||
|
||
#### [31.5.2.2.6](#ios.init) Class ios_base::Init [[ios.init]](ios.init)
|
||
|
||
[ð](#lib:ios_base::Init)
|
||
|
||
namespace std {class ios_base::Init {public: Init();
|
||
Init(const Init&) = default; ~Init();
|
||
Init& operator=(const Init&) = default; };}
|
||
|
||
[1](#ios.init-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1139)
|
||
|
||
The class Init describes an object whose construction
|
||
ensures the construction of the eight objects declared in[<iostream>](iostream.syn#header:%3ciostream%3e "31.4.1 Header <iostream> synopsis [iostream.syn]") ([[iostream.objects]](iostream.objects "31.4 Standard iostream objects")) that associate file
|
||
stream buffers with the standard C streams
|
||
provided for by the functions declared in[<cstdio>](cstdio.syn#header:%3ccstdio%3e "31.13.1 Header <cstdio> synopsis [cstdio.syn]")[.](#ios.init-1.sentence-1)
|
||
|
||
[ð](#lib:ios_base::Init,constructor)
|
||
|
||
`Init();
|
||
`
|
||
|
||
[2](#ios.init-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1154)
|
||
|
||
*Effects*: Constructs and initializes the objects cin, cout, cerr,clog, wcin, wcout, wcerr, and wclog if
|
||
they have not already been constructed and initialized[.](#ios.init-2.sentence-1)
|
||
|
||
[ð](#lib:ios_base::Init,destructor)
|
||
|
||
`~Init();
|
||
`
|
||
|
||
[3](#ios.init-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1167)
|
||
|
||
*Effects*: If there are no other instances of the class still in existence,
|
||
callscout.flush(),cerr.flush(),clog.flush(),wcout.flush(),wcerr.flush(),wclog.flush()[.](#ios.init-3.sentence-1)
|
||
|
||
#### [31.5.2.3](#fmtflags.state) State functions [[fmtflags.state]](fmtflags.state)
|
||
|
||
[ð](#lib:flags,ios_base)
|
||
|
||
`fmtflags flags() const;
|
||
`
|
||
|
||
[1](#fmtflags.state-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1188)
|
||
|
||
*Returns*: The format control information for both input and output[.](#fmtflags.state-1.sentence-1)
|
||
|
||
[ð](#lib:flags,ios_base_)
|
||
|
||
`fmtflags flags(fmtflags fmtfl);
|
||
`
|
||
|
||
[2](#fmtflags.state-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1199)
|
||
|
||
*Postconditions*: fmtfl == flags()[.](#fmtflags.state-2.sentence-1)
|
||
|
||
[3](#fmtflags.state-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1203)
|
||
|
||
*Returns*: The previous value offlags()[.](#fmtflags.state-3.sentence-1)
|
||
|
||
[ð](#lib:setf,ios_base)
|
||
|
||
`fmtflags setf(fmtflags fmtfl);
|
||
`
|
||
|
||
[4](#fmtflags.state-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1215)
|
||
|
||
*Effects*: Sets fmtfl inflags()[.](#fmtflags.state-4.sentence-1)
|
||
|
||
[5](#fmtflags.state-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1220)
|
||
|
||
*Returns*: The previous value offlags()[.](#fmtflags.state-5.sentence-1)
|
||
|
||
[ð](#lib:setf,ios_base_)
|
||
|
||
`fmtflags setf(fmtflags fmtfl, fmtflags mask);
|
||
`
|
||
|
||
[6](#fmtflags.state-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1232)
|
||
|
||
*Effects*: Clears mask inflags(),
|
||
setsfmtfl & mask inflags()[.](#fmtflags.state-6.sentence-1)
|
||
|
||
[7](#fmtflags.state-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1241)
|
||
|
||
*Returns*: The previous value offlags()[.](#fmtflags.state-7.sentence-1)
|
||
|
||
[ð](#lib:unsetf,ios_base)
|
||
|
||
`void unsetf(fmtflags mask);
|
||
`
|
||
|
||
[8](#fmtflags.state-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1253)
|
||
|
||
*Effects*: Clears mask inflags()[.](#fmtflags.state-8.sentence-1)
|
||
|
||
[ð](#lib:precision,ios_base)
|
||
|
||
`streamsize precision() const;
|
||
`
|
||
|
||
[9](#fmtflags.state-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1265)
|
||
|
||
*Returns*: The precision
|
||
to generate on certain output conversions[.](#fmtflags.state-9.sentence-1)
|
||
|
||
[ð](#lib:precision,ios_base_)
|
||
|
||
`streamsize precision(streamsize prec);
|
||
`
|
||
|
||
[10](#fmtflags.state-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1277)
|
||
|
||
*Postconditions*: prec == precision()[.](#fmtflags.state-10.sentence-1)
|
||
|
||
[11](#fmtflags.state-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1281)
|
||
|
||
*Returns*: The previous value ofprecision()[.](#fmtflags.state-11.sentence-1)
|
||
|
||
[ð](#lib:width,ios_base)
|
||
|
||
`streamsize width() const;
|
||
`
|
||
|
||
[12](#fmtflags.state-12)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1293)
|
||
|
||
*Returns*: The minimum field width (number of characters) to generate on certain output
|
||
conversions[.](#fmtflags.state-12.sentence-1)
|
||
|
||
[ð](#lib:width,ios_base_)
|
||
|
||
`streamsize width(streamsize wide);
|
||
`
|
||
|
||
[13](#fmtflags.state-13)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1305)
|
||
|
||
*Postconditions*: wide == width()[.](#fmtflags.state-13.sentence-1)
|
||
|
||
[14](#fmtflags.state-14)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1309)
|
||
|
||
*Returns*: The previous value ofwidth()[.](#fmtflags.state-14.sentence-1)
|
||
|
||
#### [31.5.2.4](#locales) Functions [[ios.base.locales]](ios.base.locales)
|
||
|
||
[ð](#lib:imbue,ios_base)
|
||
|
||
`locale imbue(const locale& loc);
|
||
`
|
||
|
||
[1](#locales-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1323)
|
||
|
||
*Effects*: Calls each registered callback pair(fn, idx) ([[ios.base.callback]](#callback "31.5.2.7 Callbacks"))
|
||
as(*fn)(imbue_event, *this, idx) at such a time that a call toios_base::getloc() from withinfn returns the new locale valueloc[.](#locales-1.sentence-1)
|
||
|
||
[2](#locales-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1336)
|
||
|
||
*Postconditions*: loc == getloc()[.](#locales-2.sentence-1)
|
||
|
||
[3](#locales-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1340)
|
||
|
||
*Returns*: The previous value ofgetloc()[.](#locales-3.sentence-1)
|
||
|
||
[ð](#lib:getloc,ios_base)
|
||
|
||
`locale getloc() const;
|
||
`
|
||
|
||
[4](#locales-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1352)
|
||
|
||
*Returns*: If no locale has been imbued, a copy of the global C++ locale,locale(),
|
||
in effect at the time of construction[.](#locales-4.sentence-1)
|
||
|
||
Otherwise, returns the imbued locale, to be used to
|
||
perform locale-dependent input and output operations[.](#locales-4.sentence-2)
|
||
|
||
#### [31.5.2.5](#ios.members.static) Static members [[ios.members.static]](ios.members.static)
|
||
|
||
[ð](#lib:sync_with_stdio,ios_base)
|
||
|
||
`static bool sync_with_stdio(bool sync = true);
|
||
`
|
||
|
||
[1](#ios.members.static-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1369)
|
||
|
||
*Effects*: If any input or output operation has occurred using the standard streams prior to the
|
||
call, the effect isimplementation-defined[.](#ios.members.static-1.sentence-1)
|
||
|
||
Otherwise, called with a false argument, it allows the standard streams to
|
||
operate independently of the standard C streams[.](#ios.members.static-1.sentence-2)
|
||
|
||
[2](#ios.members.static-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1378)
|
||
|
||
*Returns*: true if the previous state of the [standard iostream objects](iostream.objects "31.4 Standard iostream objects [iostream.objects]") was synchronized and otherwise returnsfalse[.](#ios.members.static-2.sentence-1)
|
||
|
||
The first time it is called,
|
||
the function returnstrue[.](#ios.members.static-2.sentence-2)
|
||
|
||
[3](#ios.members.static-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1388)
|
||
|
||
*Remarks*: When a standard iostream object str is*synchronized* with a standard stdio stream f, the effect of inserting a character c byfputc(f, c); is the same as the effect ofstr.rdbuf()->sputc(c); for any sequences of characters; the effect of extracting a character c byc = fgetc(f); is the same as the effect ofc = str.rdbuf()->sbumpc(); for any sequences of characters; and the effect of pushing back a character c byungetc(c, f); is the same as the effect ofstr.rdbuf()->sputbackc(c); for any sequence of characters[.](#ios.members.static-3.sentence-1)[259](#footnote-259 "This implies that operations on a standard iostream object can be mixed arbitrarily with operations on the corresponding stdio stream. In practical terms, synchronization usually means that a standard iostream object and a standard stdio object share a buffer.")
|
||
|
||
[259)](#footnote-259)[259)](#footnoteref-259)
|
||
|
||
This implies that operations on a standard iostream object can be mixed arbitrarily
|
||
with operations on the corresponding stdio stream[.](#footnote-259.sentence-1)
|
||
|
||
In practical terms, synchronization
|
||
usually means that a standard iostream object and a standard stdio object share a
|
||
buffer[.](#footnote-259.sentence-2)
|
||
|
||
#### [31.5.2.6](#storage) Storage functions [[ios.base.storage]](ios.base.storage)
|
||
|
||
[ð](#lib:xalloc,ios_base)
|
||
|
||
`static int xalloc();
|
||
`
|
||
|
||
[1](#storage-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1433)
|
||
|
||
*Returns*: *index*++[.](#storage-1.sentence-1)
|
||
|
||
[2](#storage-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1438)
|
||
|
||
*Remarks*: Concurrent access to this function by multiple threads does not result in a[data race](intro.multithread#def:data_race "6.10.2 Multi-threaded executions and data races [intro.multithread]")[.](#storage-2.sentence-1)
|
||
|
||
[ð](#lib:iword,ios_base)
|
||
|
||
`long& iword(int idx);
|
||
`
|
||
|
||
[3](#storage-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1450)
|
||
|
||
*Preconditions*: idx is a value obtained by a call to xalloc[.](#storage-3.sentence-1)
|
||
|
||
[4](#storage-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1454)
|
||
|
||
*Effects*: If *iarray* is a null pointer, allocates an array oflong of unspecified size and stores a pointer to its first element in*iarray*[.](#storage-4.sentence-1)
|
||
|
||
The function then extends the array pointed at by*iarray* as necessary to include the element*iarray*[idx][.](#storage-4.sentence-2)
|
||
|
||
Each newly allocated element of the array is initialized to zero[.](#storage-4.sentence-3)
|
||
|
||
The reference returned is invalid after any other operation on the
|
||
object[.](#storage-4.sentence-4)[260](#footnote-260 "An implementation is free to implement both the integer array pointed at by iarray and the pointer array pointed at by parray as sparse data structures, possibly with a one-element cache for each.")
|
||
|
||
However, the value of the storage referred to is retained, so
|
||
that until the next call tocopyfmt,
|
||
callingiword with the same index yields another reference to the same value[.](#storage-4.sentence-5)
|
||
|
||
If the function fails[261](#footnote-261 "For example, because it cannot allocate space.") and*this is a base class subobject of abasic_ios<> object or subobject, the effect is equivalent to callingbasic_ios<>::setstate(badbit) on the derived object (which may throwfailure)[.](#storage-4.sentence-6)
|
||
|
||
[5](#storage-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1491)
|
||
|
||
*Returns*: On success*iarray*[idx][.](#storage-5.sentence-1)
|
||
|
||
On failure, a validlong& initialized to 0[.](#storage-5.sentence-2)
|
||
|
||
[ð](#lib:pword,ios_base)
|
||
|
||
`void*& pword(int idx);
|
||
`
|
||
|
||
[6](#storage-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1506)
|
||
|
||
*Preconditions*: idx is a value obtained by a call to xalloc[.](#storage-6.sentence-1)
|
||
|
||
[7](#storage-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1510)
|
||
|
||
*Effects*: If *parray* is a null pointer, allocates an array of
|
||
pointers to void of unspecified size and stores a pointer to
|
||
its
|
||
first element in *parray*[.](#storage-7.sentence-1)
|
||
|
||
The function then extends the array
|
||
pointed at by *parray* as necessary to include the element*parray*[idx][.](#storage-7.sentence-2)
|
||
|
||
Each newly allocated element of the array is initialized to a null
|
||
pointer[.](#storage-7.sentence-3)
|
||
|
||
The reference returned is invalid after any other operation on the
|
||
object[.](#storage-7.sentence-4)
|
||
|
||
However, the value of the storage referred to is retained, so
|
||
that until the next call tocopyfmt,
|
||
callingpword with the same index yields another reference to the same value[.](#storage-7.sentence-5)
|
||
|
||
If the function fails[262](#footnote-262 "For example, because it cannot allocate space.") and*this is a base class subobject of abasic_ios<> object or subobject, the effect is equivalent to callingbasic_ios<>::setstate(badbit) on the derived object (which may throwfailure)[.](#storage-7.sentence-6)
|
||
|
||
[8](#storage-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1542)
|
||
|
||
*Returns*: On successparray[idx][.](#storage-8.sentence-1)
|
||
|
||
On failure a validvoid*& initialized to 0[.](#storage-8.sentence-2)
|
||
|
||
[9](#storage-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1550)
|
||
|
||
*Remarks*: After a subsequent call topword(int) for the same object, the earlier return value may no longer be valid[.](#storage-9.sentence-1)
|
||
|
||
[260)](#footnote-260)[260)](#footnoteref-260)
|
||
|
||
An implementation is free to implement both the integer
|
||
array pointed at by *iarray* and the pointer array pointed at by*parray* as sparse data structures, possibly with a one-element
|
||
cache for each[.](#footnote-260.sentence-1)
|
||
|
||
[261)](#footnote-261)[261)](#footnoteref-261)
|
||
|
||
For example, because it cannot allocate space[.](#footnote-261.sentence-1)
|
||
|
||
[262)](#footnote-262)[262)](#footnoteref-262)
|
||
|
||
For example, because it cannot allocate space[.](#footnote-262.sentence-1)
|
||
|
||
#### [31.5.2.7](#callback) Callbacks [[ios.base.callback]](ios.base.callback)
|
||
|
||
[ð](#lib:register_callback,ios_base)
|
||
|
||
`void register_callback(event_callback fn, int idx);
|
||
`
|
||
|
||
[1](#callback-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1565)
|
||
|
||
*Preconditions*: The functionfn does not throw exceptions[.](#callback-1.sentence-1)
|
||
|
||
[2](#callback-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1571)
|
||
|
||
*Effects*: Registers the pair(fn, idx) such that during calls toimbue() ([[ios.base.locales]](#locales "31.5.2.4 Functions")),copyfmt(),
|
||
or~ios_base() ([[ios.base.cons]](#cons "31.5.2.8 Constructors and destructor")),
|
||
the functionfn is called with argumentidx[.](#callback-2.sentence-1)
|
||
|
||
Functions registered are called when an event occurs, in opposite order of
|
||
registration[.](#callback-2.sentence-2)
|
||
|
||
Functions registered while a callback function is active are not called until the next event[.](#callback-2.sentence-3)
|
||
|
||
[3](#callback-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1588)
|
||
|
||
*Remarks*: Identical pairs are not merged[.](#callback-3.sentence-1)
|
||
|
||
A function registered twice will be called twice[.](#callback-3.sentence-2)
|
||
|
||
#### [31.5.2.8](#cons) Constructors and destructor [[ios.base.cons]](ios.base.cons)
|
||
|
||
[ð](#lib:ios_base,constructor)
|
||
|
||
`ios_base();
|
||
`
|
||
|
||
[1](#cons-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1602)
|
||
|
||
*Effects*: Eachios_base member has an indeterminate value after construction[.](#cons-1.sentence-1)
|
||
|
||
The object's members shall be initialized by callingbasic_ios::init before the object's first use or before it is destroyed, whichever comes first; otherwise
|
||
the behavior is undefined[.](#cons-1.sentence-2)
|
||
|
||
[ð](#lib:ios_base,destructor)
|
||
|
||
`~ios_base();
|
||
`
|
||
|
||
[2](#cons-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L1619)
|
||
|
||
*Effects*: Calls each registered callback pair(fn, idx) ([[ios.base.callback]](#callback "31.5.2.7 Callbacks")) as(*fn)(erase_event, *this, idx) at such time that anyios_base member function called from withinfn has well-defined results[.](#cons-2.sentence-1)
|
||
|
||
Then, any memory obtained is deallocated[.](#cons-2.sentence-2)
|