std::ios_base
The class ios_base is a multipurpose class that serves as the base class for all I/O stream classes. It maintains several kinds of data:
Typical implementation holds member constants corresponding to all values of fmtflags , iostate , openmode , and seekdir shown below, member variables to maintain current precision, width, and formatting flags, the exception mask, the buffer error state, a resizeable container holding the callbacks, the currently imbued locale, the private storage, and a static integer variable for xalloc() .
std:: ios_base
Base class for the entire hierarchy of stream classes in the standard input/output library, describing the most basic part of a stream which is common to all stream objects, independently of their character type.
It has no public constructors, and thus no objects of this class can be declared.
Both ios_base and its derived class basic_ios define the components of streams that do not depend on whether the stream is an input or an output stream: ios_base describes the members that are independent of the template parameters (i.e. the character type and traits), while basic_ios describes the members that do depend on them.
More specifically, the ios_base class maintains the following information of a stream:
Ios base c что это
Base class that defines member types and maintains data for classes that inherit from it
Synopsis
Description
The class ios_base defines several member types:
A class failure derived from exception
Three Bitmask Types : fmtflags , iostate , and openmode
Two enumerated types: seekdir and event
It maintains several kinds of data:
Control information that influences how to interpret (format) input sequences and how to generate (format) output sequences
Locale object used within the stream classes
Arrays of user data used for storage management
A number of static constant data members
Additional information that is stored by the program for its private use
Interface
Member Types
The type fmtflags is a bitmask type. See Bitmask Type for more information. Setting its elements has the following effects:
Generates a + sign in nonnegative generated numeric output.
Generates a prefix indicating the numeric base of generated integer output
Replaces certain lowercase letters with their uppercase equivalents in generated output
Generates a decimal-point character unconditionally in generated floating-point output
Inserts and extracts bool type in alphabetic format
Flushes output after each output operation
Adds fill characters at a designated internal point in certain generated output. If no such point is designated, it’s identical to right .
Adds fill characters on the right (final positions) of certain generated output
Adds fill characters on the left (initial positions) of certain generated output
Converts integer input or generates integer output in decimal base
Converts integer input or generates integer output in hexadecimal base
Converts integer input or generates integer output in octal base
Generates floating-point output in fixed-point notation
Generates floating-point output in scientific notation
Skips leading white space before certain input operation.
The following constants are also defined:
left | right | internal
The type iostate is a bitmask type. See Bitmask Types for more information. Setting its elements has the following effects:
Indicates a loss of integrity in an input or output sequence.
Indicates that an input operation reached the end of an input sequence.
Indicates that an input operation failed to read the expected characters, or that an output operation failed to generate the desired characters.
Initial stream state, no other bit is set.
The type openmode is a bitmask type. See Bitmask Types for more information. Setting its elements has the following effects:
Attempts to seek to the end of the file immediately before each write. Each seek and the subsequent write are performed as a single atomic operation.
Attempts to seek to the end of the file immediately after opening. The opening and the subsequent seek may be performed as two operations.
Performs input and output in binary mode rather than text mode. In binary mode the stream treats the contents of the file as a sequence of bytes without interpreting in any special way, certain sequences of characters such as carriage returns and line feeds.
Opens for input.
Opens for output.
Attempts to truncate an existing file to 0 size immediately after opening. The file must be opened for output (i.e., with out ). The opening and the subsequent truncation are performed as a single atomic operation.
Successfully opens the file if and only if a file with that name already exists. The checking for the file’s existence and its subsequent creation are performed as a single atomic operation.
Successfully creates the file if and only if a file with that name does not already exist and the file is being opened for output (i.e., with out ). The checking for the file’s existence and its subsequent creation are performed as a single atomic operation.
The type seekdir is an enumerated type. Setting its elements has the following effects:
Requests a seek relative to the beginning of the stream.
Requests a seek relative to the current position within the sequence.
Requests a seek relative to the current end of the sequence.
Constants of the enumerated type event are passed as arguments to user-defined callback functions registered with the stream objects via register_callback() :
The stream object is being erased.
A new locale is being imbued in the stream object.
The copyfmt() member function has been called on an object.
The type event_callback is the type of the callback function used as a parameter in the function register_callback . These functions allow you to use the iword , pword mechanism in an exception-safe environment.
Protected Constructor
The ios_base members have an indeterminate value after construction.
Destructors
Destroys an object of class ios_base . Calls each registered callback pair (fn, index) as (*fn)(erase_event,*this, index) at such a time that any ios_base member function called from within fn has well-defined results.
Public Member Functions
Returns the format control information for both input and output.
Sets flags() to fmtfl and returns the previous value of flags() .
Sets flags() to (fmtfl | flags()) and returns the previous value of flags() .
Clears mask in flags() , sets (fmtfl & mask) in flags() , and returns the previous value of flags() .
Clears mask in flags() .
Returns the imbued locale, which is used to perform locale-dependent input and output operations. The default locale, locale::locale() , is used if no other locale object has been imbued in the stream by a call to the imbue function.
Saves the value returned by getloc() , then assigns loc to a private variable and calls each registered callback pair (fn, index) as (*fn)(imbue_event,*this, index) . It then returns the previously saved value.
If iarray is a null pointer, allocates an array of long s of sufficient size, and stores a pointer to its first element in iarray . The function then extends the array pointed to by iarray , as necessary, to include the element iarray[idx] . Each newly allocated element of the array is initialized to 0 . The reference returned may become invalid after another call to the object’s iword() member with a different index, after a call to its copyfmt() member, or when the object is destroyed. If the function fails, it sets failbit , which may throw an exception. On success, the function returns iarray[idx] ; otherwise, a valid long& initialized to 0 .
Returns the precision (number of digits after the decimal point) to generate on certain output conversions.
Saves the precision, then sets it to prec and returns the previously saved value.
If parray is a null pointer, allocates an array of void* of sufficient size, and stores a pointer to its first element in parray . The function then extends the array pointed at by parray , as necessary, to include the element parray[idx] . Each newly allocated element of the array is initialized to 0 . The reference returned may become invalid after another call to the object’s pword member with a different index, after a call to its copyfmt() member, or when the object is destroyed. If the function fails, it sets failbit , which may throw an exception. On success, the function returns parray[idx] ; otherwise, a valid void*& initialized to 0 .
Registers the pair (fn, index) such that during calls to imbue() , copyfmt() , or
ios_base() , the function fn is called with argument index . Functions registered are called when an event occurs, in opposite order of registration. Functions registered while a callback function is active are not called until the next event. Identical pairs are not merged; a function registered twice is called twice per event.
When called with a false argument, allows the C++ standard streams to operate independently of the standard C streams, which greatly improves performance. When called with a true argument, restores the default synchronization. The return value of the function is the status of the synchronization at the time of the call.
Returns the field width (number of characters) to generate on certain output conversions.
Saves the field width, sets it to wide , and returns the previously saved value.
Returns the next static index that can be used with pword and iword . This is useful if you want to share data between several stream objects.
Class failure
The class failure defines the base class for the types of all objects thrown as exceptions by functions in the iostream s library. It reports errors detected during stream buffer operations.
Constructs an object of class failure , initializing the base class with exception(msg).
Public Member Function
Returns the message msg with which the exception was created.
Class Init
The class Init describes an object whose construction ensures the construction of the eight objects declared in <iostream> , which associates file stream buffers with the standard C streams.
Nonmember Functions
The following functions are ios_base manipulators.
Calls str.setf(ios_base::boolalpha) and returns str .
Calls str.setf(ios_base::dec, ios_base::basefield) and returns str .
Calls str.setf(ios_base::fixed, ios_base::floatfield) and returns str .
Calls str.setf(ios_base::hex, ios_base::basefield) and returns str .
Calls str.setf(ios_base::internal, ios_base::adjustfield) and returns str .
Calls str.setf(ios_base::left, ios_base::adjustfield) and returns str .
Calls str.unsetf(ios_base::boolalpha) and returns str.
Calls str.unsetf(ios_base::showbase) and returns str .
Calls str.unsetf(ios_base::showpoint) and returns str .
Calls str.unsetf(ios_base::showpos) and returns str .
Calls str.unsetf(ios_base::skipws) and returns str .
Calls str.unsetf(ios_base::unitbuf) and returns str .
Calls str.unsetf(ios_base::uppercase) and returns str .
Calls str.setf(ios_base::oct, ios_base::basefield) and returns str .
Calls str.setf(ios_base::right, ios_base::adjustfield) and returns str .
Calls str.setf(ios_base::scientific, ios_base::floatfield) and returns str .
Calls str.setf(ios_base::showbase) and returns str .
Calls str.setf(ios_base::showpoint) and returns s tr .
Calls str.setf(ios_base::showpos) and returns str .
Calls str.setf(ios_base::skipws) and returns str .
Calls str.setf(ios_base::unitbuf) and returns str .
Calls str.setf(ios_base::uppercase) and returns str .
See Also
Standards Conformance
ISO/IEC 14882:1998 — International Standard for Information Systems —Programming Language C++, Section 27.4.2
std::ios_base Class Reference
This class defines everything that can be defined about I/O that does not depend on the type of characters being input or output. Most people will only see ios_base when they need to specify the full name of the various I/O flags (e.g., the openmodes).
Definition at line 160 of file ios_base.h.
Member Typedef Documentation
|
|
|
|
|
|
| fmtfl | The new flags to set. |
Returns: The previous format control flags. This function overwrites all the format flags with fmtfl.
Access to format flags.
Returns: The format control flags for both input and output.
Definition at line 474 of file ios_base.h.
Returns: The locale currently in effect. If imbue(loc) has previously been called, then this function returns loc . Otherwise, it returns a copy of std::locale() , the global C++ locale.
Definition at line 616 of file ios_base.h.
Setting a new locale.
Parameters:
| loc | The new locale. |
Returns: The previous locale. Sets the new locale for this stream, and [XXX does something with callbacks].
Parameters:
| prec | The new precision value. |
Returns: The previous value of precision().
Returns: The precision to generate on certain output operations.
Definition at line 544 of file ios_base.h.
Setting new format flags.
Parameters:
| fmtfl | Additional flags to set. |
| mask | The flags mask for fmtfl. |
Returns: The previous format control flags. This function clears mask in the format flags, then sets fmtfl & mask. An example mask is ios_base::adjustfield .
Setting new format flags.
Parameters:
| fmtfl | Additional flags to set. |
Returns: The previous format control flags. This function sets additional flags in format control. Flags that were previously set remain set.
Definition at line 500 of file ios_base.h.
Interaction with the standard C I/O objects.
Parameters:
| sync | Whether to synchronize or not. |
Returns: True if the standard streams were previously synchronized. The synchronization referred to is only that between the standard C facilities (e.g., stdout) and the standard C++ objects (e.g., cout). User-declared streams are unaffected. See http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#8 for more.
Clearing format flags.
Parameters:
| mask | The flags to unset. |
This function clears mask in the format flags.
Definition at line 532 of file ios_base.h.
Parameters:
| wide | The new width value. |
Returns: The previous value of width().
Returns: The minimum field width to generate on output operations. «Minimum field width» refers to the number of characters.
Definition at line 566 of file ios_base.h.
Member Data Documentation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|