Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/io"

From cppreference.com
< cpp
(iomanips and other top-level things other than the main class hierarchy and the class-specific instatiations of std::swap)
m (wording tweaks for stream{off/pos/size}, deprecated IO classes)
Line 34: Line 34:
 
{{dcl list tclass | cpp/io/basic_ostringstream | implements high-level string stream output operations}}
 
{{dcl list tclass | cpp/io/basic_ostringstream | implements high-level string stream output operations}}
 
{{dcl list tclass | cpp/io/basic_stringstream | implements high-level string stream input/output operations}}
 
{{dcl list tclass | cpp/io/basic_stringstream | implements high-level string stream input/output operations}}
 +
{{dcl list h2 | Array I/O implementations}}
 +
{{dcl list class | cpp/io/strstreambuf | notes={{mark deprecated}} | implements raw character array device}}
 +
{{dcl list class | cpp/io/istrstream | notes={{mark deprecated}} | implements character array input operations}}
 +
{{dcl list class | cpp/io/ostrstream | notes={{mark deprecated}} | implements character array output operations}}
 
{{dcl list end}}
 
{{dcl list end}}
  
Line 90: Line 94:
 
{{dcl list begin}}
 
{{dcl list begin}}
 
{{dcl list header | ios }}
 
{{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 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/streampos | represents a position in a narrow character streams}}
 
{{dcl list ptclass | cpp/io/wstreampos | represents a position in wide character streams}}
 
{{dcl list ptclass | cpp/io/wstreampos | represents a position in wide character streams}}
 +
{{dcl list typedef | cpp/io/streamoff | represents offset from a streampos, sufficient to represent any file size }}
 +
{{dcl list typedef | cpp/io/streamsize | represents the number of characters transferred in an I/O operation or the size of an I/O buffer}}
 
{{dcl list end}}
 
{{dcl list end}}
  

Revision as of 11:37, 2 October 2011

Template:cpp/io/sidebar

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

Contents

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)
Array I/O implementations
(deprecated)
implements raw character array device
(class)
(deprecated)
implements character array input operations
(class)
(deprecated)
implements character array output operations
(class)

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>
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)
represents offset from a streampos, sufficient to represent any file size
(typedef)
represents the number of characters transferred in an I/O operation or the size of an I/O buffer
(typedef)

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)
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

Template:dcl list ptfun
Defined in header <ios>
(C++11)
the system error category enumeration of IO error codes
(class)
constructs an iostream error category
(function)
constructs an iostream error code
(function)
constructs an iostream error_condition
(function)

C-style input/output