Oracle® Solaris Studio 12.4: C++ User's Guide

Exit Print View

Updated: March 2015
 
 

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 existing 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 standard mode. libCstd, which includes the standard iostream library, is linked by default.

example% CC prog2.cc -o prog2

11.4.1.1 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 Solaris Studio releases.