iostream: the ISO C++ input/output library.
Also the name of a class within the library, see below.
To write output to and read from standard input in C++ you do:
int age;
string first_name;
cout << "What is your first name and age? ";
cin >> first_name >> age;
cin is an object of class istream, and cout
is a member of class ostream.
Similar for files:
int xp;
fstream file("e2.xml");
file << "<xp>" << xp << "</xp>\n";
Simplified family tree of iostream classes:
ios_base streambuf
| |
ios |
/ \ |
istream ostream stringbuf, filebuf
/ \ / \
ifstream iostream ofstream
\ /
\-------fstream----/
*istringstream, ostringstream, stringstream
follow the same pattern as ifstream, ofstream, fstream
respectively.
ios_base and ios usually are not used by programmers,
but are present for base characteristics of the iostream classes. iostream
is very easy to extend. An {i,o}stream class takes a streambuf
or derived object and buffers output to/from it. It is very easy to write a
socketbuf or windowbuf, for example, to input/output
to/from a socket or window system.
iostream headers used to be included as #include <iostream.h>,
but the current standard uses #include <iostream>
- further departing from C. The theory is to lift the concept of include
files to a higher level - you are including a library, not a file. However,
in practice, this is simply a file called "iostream" rather than "iostream.h".
Some compilers (g++) simply wrap a namespace std { #include <iostream.h>
}. Others (MSVC) completely rewrote <iostream> to
stay current with the moving standard, and leave <iostream.h>
as it was (and incompatible with each other).