JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.2: C++ User's Guide
search filter icon
search icon

Document Information

Preface

Part I C++ Compiler

1.  The C++ Compiler

2.  Using the C++ Compiler

3.  Using the C++ Compiler Options

Part II Writing C++ Programs

4.  Language Extensions

5.  Program Organization

6.  Creating and Using Templates

7.  Compiling Templates

8.  Exception Handling

9.  Improving Program Performance

10.  Building Multithreaded Programs

Part III Libraries

11.  Using Libraries

12.  Using The C++ Standard Library

13.  Using the Classic iostream Library

13.1 Predefined iostreams

13.2 Basic Structure of iostream Interaction

13.3 Using the Classic iostream Library

13.3.1 Output Using iostream

13.3.1.1 Defining Your Own Insertion Operator

13.3.1.2 Handling Output Errors

13.3.1.3 Flushing

13.3.1.4 Binary Output

13.3.2 Input Using iostream

13.3.3 Defining Your Own Extraction Operators

13.3.4 Using the char* Extractor

13.3.5 Reading Any Single Character

13.3.6 Binary Input

13.3.7 Peeking at Input

13.3.8 Extracting Whitespace

13.3.9 Handling Input Errors

13.3.10 Using iostreams With stdio

13.4 Creating iostreams

13.4.1 Dealing With Files Using Class fstream

13.4.1.1 Open Mode

13.4.1.2 Declaring an fstream Without Specifying a File

13.4.1.3 Opening and Closing Files

13.4.1.4 Opening a File Using a File Descriptor

13.4.1.5 Repositioning Within a File

13.5 Assignment of iostreams

13.6 Format Control

13.7 Manipulators

13.7.1 Using Plain Manipulators

13.7.2 Parameterized Manipulators

13.8 Strstreams: iostreams for Arrays

13.9 Stdiobufs: iostreams for stdio Files

13.10 Streambufs

13.10.1 Working With Streambufs

13.10.1.1 Position of Pointers

13.10.2 Using Streambufs

13.11 iostream Man Pages

13.12 iostream Terminology

14.  Using the Complex Arithmetic Library

15.  Building Libraries

Part IV Appendixes

A.  C++ Compiler Options

B.  Pragmas

Glossary

Index

13.2 Basic Structure of iostream Interaction

By including the iostream library, a program can use any number of input or output streams. Each stream has some source or sink, which may be one of the following:

A stream can be restricted to input or output, or a single stream can allow both input and output. The iostream library implements these streams using two processing layers.

Standard input, output, and error are handled by special class objects derived from class istream or ostream.

The ifstream, ofstream, and fstream classes, which are derived from istream, ostream, and iostream respectively, handle input and output with files.

The istrstream, ostrstream, and strstream classes, which are derived from istream, ostream, and iostream respectively, handle input and output to and from arrays of characters.

When you open an input or output stream, you create an object of one of these types, and associate the streambuf member of the stream with a device or file. You generally do this association through the stream constructor, so you don’t work with the streambuf directly. The iostream library predefines stream objects for the standard input, standard output, and error output, so you don’t have to create your own objects for those streams.

You use operators or iostream member functions to insert data into a stream (output) or extract data from a stream (input), and to control the format of data that you insert or extract.

When you want to insert and extract a new data type—one of your classes—you generally overload the insertion and extraction operators.