Generally, two steps are involved in using a class library:
Include the appropriate header in your source code.
Link your program with the object library.
The C++ compiler provides two implementations of iostreams:
Classic iostreams. This term refers to the iostreams library shipped with the C++ 4.0, 4.0.1, 4.1, and 4.2 compilers, and earlier with the cfront-based 3.0.1 compiler. There is no standard for this library. It is available in libiostream.
Standard iostreams. This is part of the version of the standard C++ library you use—libCstd, libstlport, libstdcxx, or the g++ runtime library. The standard version of iostreams is neither binary-compatible nor entirely source-compatible with the classic iostreams library.
If you have old C++ sources, your code might look like the following example, which uses classic iostreams.
// file prog1.cc #include <iostream.h> int main() { cout << "Hello, world!" << endl; return 0; }
The following example uses standard iostreams.
// file prog2.cc #include <iostream> int main() { std::cout << "Hello, world!" << std::endl; return 0; }
The following command compiles and links prog2.cc into an executable program called prog2. The program is compiled in -compat=5 mode. libCstd, which includes the standard iostream library, is linked by default.
example% CC -compat=5 prog2.cc -o prog2
The so-called “Classic” iostreams is the original 1986 version of iostreams, which was replaced in the C++ standard. It is selected through the -library=iostream option. No two implementations of “classic” iostreams are the same, so apart from being obsolete, code using it is not portable. Note that this library and option will be discontinued in future Oracle Developer Studio releases.
The following table shows the compiler options for linking the C++ libraries. See –library=l[,l...] for more information.
|