Go to main content
Oracle® Developer Studio 12.6: C++ User's Guide

Exit Print View

Updated: July 2017

11.4 Using Class Libraries

Generally, two steps are involved in using a class library:

  1. Include the appropriate header in your source code.

  2. Link your program with the object library.

11.4.1 iostream 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 Note About Classic iostreams

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.

11.4.2 Linking C++ Libraries

The following table shows the compiler options for linking the C++ libraries. See –library=l[,l...] for more information.

Table 24  Compiler Options for Linking C++ Libraries
Classic iostream
Garbage collection
STLport version 4
STLport version 4 debug
Apache stdcxx version 4
Sun Performance Library

Note -  In -std=c++03, -std=c++11, and -std=c++14 modes, only the gc and sunperf libraries can be added. There are no options for different versions of the C++ standard library.