Difference between revisions of "cpp/io"
(use dcl list for consistency) |
(iomanips and other top-level things other than the main class hierarchy and the class-specific instatiations of std::swap) |
||
Line 41: | Line 41: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
+ | typedef basic_ios<char> ios; | ||
+ | typedef basic_ios<wchar_t> wios; | ||
+ | |||
typedef basic_streambuf<char> streambuf; | typedef basic_streambuf<char> streambuf; | ||
typedef basic_streambuf<wchar_t> wstreambuf; | typedef basic_streambuf<wchar_t> wstreambuf; | ||
Line 81: | Line 84: | ||
extern wostream wclog; | extern wostream wclog; | ||
</source> | </source> | ||
+ | |||
+ | ===Types=== | ||
+ | |||
+ | The following auxiliary type are defined: | ||
+ | {{dcl list begin}} | ||
+ | {{dcl list header | ios }} | ||
+ | {{dcl list typedef | cpp/io/streamoff | represent file size or any offset within a stream buffer }} | ||
+ | {{dcl list typedef | cpp/io/streamsize | represent the size of a stream buffer or the number of characters transferred in an IO operation }} | ||
+ | {{dcl list tclass | cpp/io/fpos | represents a position in a stream }} | ||
+ | {{dcl list ptclass | cpp/io/streampos | represents a position in a narrow character streams}} | ||
+ | {{dcl list ptclass | cpp/io/wstreampos | represents a position in wide character streams}} | ||
+ | {{dcl list end}} | ||
===Manipulators=== | ===Manipulators=== | ||
Line 86: | Line 101: | ||
Several manipulators are defined to control the formatting of input/output operations on streams. | Several manipulators are defined to control the formatting of input/output operations on streams. | ||
− | {{ | + | {{dcl list begin}} |
+ | {{dcl list header | ios }} | ||
+ | {{dcl list fun | cpp/io/boolalpha | title=boolalpha<br>noboolalpha | switches between textual and numeric representation of booleans}} | ||
+ | {{dcl list fun | cpp/io/showbase | title=showbase<br>noshowbase | controls whether prefix is used to indicate numeric base }} | ||
+ | {{dcl list fun | cpp/io/showpoint | title=showpoint<br>noshowpoint | controls whether decimal point is always included in floating-point representation }} | ||
+ | {{dcl list fun | cpp/io/showpos | title=snowpos<br>noshowpos| controls whether the + sign used with non-negative numbers}} | ||
+ | {{dcl list fun | cpp/io/skipws | title=skipws<br>noskipws| controls whether leading whitespace is skipped on input}} | ||
+ | {{dcl list fun | cpp/io/uppercase | title=uppercase<br>nouppercase | controls whether uppercase characters are used with some output formats }} | ||
+ | {{dcl list fun | cpp/io/unitbuf | title=unitbuf<br>nounitbuf | controls whether output is flushed after each operation}} | ||
+ | {{dcl list fun | cpp/io/left | title=internal<br>left<br>right | sets the placement of fill characters }} | ||
+ | {{dcl list fun | cpp/io/hex | title=dec<br>hex<br>oct | changes the base used for integer I/O}} | ||
+ | {{dcl list fun | cpp/io/fixed | title=fixed<br>scientific<br>hexfloat<br>defaultfloat | notes=<br><br>{{mark c++11}}<br>{{mark c++11}} | changes formatting used for floating-point I/O}} | ||
+ | {{dcl list header | istream}} | ||
+ | {{dcl list tfun | cpp/io/ws | consumes whitespace}} | ||
+ | {{dcl list header | ostream}} | ||
+ | {{dcl list tfun | cpp/io/ends | outputs '\0'}} | ||
+ | {{dcl list tfun | cpp/io/flush | flushes the output stream}} | ||
+ | {{dcl list tfun | cpp/io/endl | outputs '\n' and flushes the output stream}} | ||
+ | {{dcl list header | iomanip}} | ||
+ | {{dcl list fun | cpp/io/resetiosflags | clears the specified ios_base flags}} | ||
+ | {{dcl list fun | cpp/io/setiosflags | sets the specified ios_base flags}} | ||
+ | {{dcl list fun | cpp/io/setbase | change the base used for integer I/O}} | ||
+ | {{dcl list fun | cpp/io/setfill | change fill character}} | ||
+ | {{dcl list fun | cpp/io/setprecision | change floating-point precision}} | ||
+ | {{dcl list fun | cpp/io/setw | change the width of the next output}} | ||
+ | {{dcl list tfun | cpp/io/get_money | parses a monetary value | notes={{mark c++11}}}} | ||
+ | {{dcl list tfun | cpp/io/put_money | formats and outputs a monetary value| notes={{mark c++11}}}} | ||
+ | {{dcl list tfun | cpp/io/get_time | parses a date/time value of specified format| notes={{mark c++11}}}} | ||
+ | {{dcl list tfun | cpp/io/put_time | formats and outputs a date/time value according to the specified format| notes={{mark c++11}}}} | ||
+ | {{dcl list end}} | ||
+ | |||
+ | ===Error category interface=== | ||
+ | {{dcl list begin}} | ||
+ | {{dcl list header | ios }} | ||
+ | {{dcl list class | cpp/io/io_errc | notes={{mark c++11}} | the system error category enumeration of IO error codes}} | ||
+ | {{dcl list ptfun | cpp/io/is_error_code_enum | title=is_error_code_enum{{small|(std::io_errc)}}| notes={{mark c++11}} | extends the type trait {{cpp|std::is_error_code_enum}} to identify iostream error codes}} | ||
+ | {{dcl list fun | cpp/io/iostream_category | notes={{mark c++11}} | constructs an iostream error category}} | ||
+ | {{dcl list fun | cpp/io/make_error_code | title=make_error_code{{small|(std::io_errc)}} | notes={{mark c++11}} | constructs an iostream error code}} | ||
+ | {{dcl list fun | cpp/io/make_error_condition | title=make_error_condition{{small|(std::io_errc)}} | notes={{mark c++11}} | constructs an iostream error_condition}} | ||
+ | {{dcl list end}} | ||
===[[cpp/io/c | C-style input/output]]=== | ===[[cpp/io/c | C-style input/output]]=== |
Revision as of 10:35, 2 October 2011
Standard input/output library is organized in such a way that the underlying device of an input/output operation is abstracted. In this way the same code can handle input/output to a file, memory stream, or custom adaptor device interpreting the data on the fly, e.g. compressing it. Most of the classes are templated, so they can be adapted to any basic character type. Separate typedefs are provided for the most common basic character types (Template:cpp and Template:cpp).
Error: Image is invalid or non-existent.
Inheritance diagram
Abstraction | ||
abstracts a raw device (class template) | ||
wraps a given abstract device (Template:cpp) and provides high-level input interface (class template) | ||
wraps a given abstract device (Template:cpp) and provides high-level output interface (class template) | ||
wraps a given abstract device (Template:cpp) and provides high-level input/output interface (class template) | ||
File I/0 implementation | ||
implements raw file device (class template) | ||
implements high-level file stream input operations (class template) | ||
implements high-level file stream output operations (class template) | ||
implements high-level file stream input/output operations (class template) | ||
String I/0 implementation | ||
implements raw string device (class template) | ||
implements high-level string stream input operations (class template) | ||
implements high-level string stream output operations (class template) | ||
implements high-level string stream input/output operations (class template) |
Typedefs
The following typedefs for common character types are provided:
typedef basic_ios<char> ios; typedef basic_ios<wchar_t> wios; typedef basic_streambuf<char> streambuf; typedef basic_streambuf<wchar_t> wstreambuf; typedef basic_filebuf<char> filebuf; typedef basic_filebuf<wchar_t> wfilebuf; typedef basic_stringbuf<char> stringbuf; typedef basic_stringbuf<wchar_t> wstringbuf; typedef basic_istream<char> istream; typedef basic_istream<wchar_t> wistream; typedef basic_ostream<char> ostream; typedef basic_ostream<wchar_t> wostream; typedef basic_iostream<char> iostream; typedef basic_iostream<wchar_t> wiostream; typedef basic_ifstream<char> ifstream; typedef basic_ifstream<wchar_t> wifstream; typedef basic_ofstream<char> ofstream; typedef basic_ofstream<wchar_t> wofstream; typedef basic_fstream<char> fstream; typedef basic_fstream<wchar_t> wfstream; typedef basic_istringstream<char> istringstream; typedef basic_istringstream<wchar_t> wistringstream; typedef basic_ostringstream<char> ostringstream; typedef basic_ostringstream<wchar_t> wostringstream; typedef basic_stringstream<char> stringstream; typedef basic_stringstream<wchar_t> wstringstream;
Predefined standard stream objects:
extern istream cin; //standard input (stdin) extern wistream wcin; extern ostream cout; //standard output (stdout) extern wostream wcout; extern ostream cerr; //standard error (stderr) extern wostream wcerr; extern ostream clog; //standard log (stdlog) extern wostream wclog;
Types
The following auxiliary type are defined:
Defined in header
<ios> | |
represent file size or any offset within a stream buffer (typedef) | |
represent the size of a stream buffer or the number of characters transferred in an IO operation (typedef) | |
represents a position in a stream (class template) | |
represents a position in a narrow character streams (class template specialization) | |
represents a position in wide character streams (class template specialization) |
Manipulators
Several manipulators are defined to control the formatting of input/output operations on streams.
Defined in header
<ios> | |
switches between textual and numeric representation of booleans (function) | |
controls whether prefix is used to indicate numeric base (function) | |
controls whether decimal point is always included in floating-point representation (function) | |
controls whether the + sign used with non-negative numbers (function) | |
controls whether leading whitespace is skipped on input (function) | |
controls whether uppercase characters are used with some output formats (function) | |
controls whether output is flushed after each operation (function) | |
sets the placement of fill characters (function) | |
changes the base used for integer I/O (function) | |
(C++11)(C++11) |
changes formatting used for floating-point I/O (function) |
Defined in header
<istream> | |
consumes whitespace (function template) | |
Defined in header
<ostream> | |
outputs '\0' (function template) | |
flushes the output stream (function template) | |
outputs '\n' and flushes the output stream (function template) | |
Defined in header
<iomanip> | |
clears the specified ios_base flags (function) | |
sets the specified ios_base flags (function) | |
change the base used for integer I/O (function) | |
change fill character (function) | |
change floating-point precision (function) | |
change the width of the next output (function) | |
(C++11) |
parses a monetary value (function template) |
(C++11) |
formats and outputs a monetary value (function template) |
(C++11) |
parses a date/time value of specified format (function template) |
(C++11) |
formats and outputs a date/time value according to the specified format (function template) |
Error category interface
Defined in header
<ios> | |
(C++11) |
the system error category enumeration of IO error codes (class) |
(C++11) |
constructs an iostream error category (function) |
constructs an iostream error code (function) | |
constructs an iostream error_condition (function) |