C++ Migration Guide

Iostreams

The C++ 4.2 compiler implements classic iostreams, which never had a formal definition. The implementation is compatible with the version released with Cfront (1990), with some bug fixes.

Standard C++ defines a new and expanded iostreams (standard iostreams). It is better defined, feature-rich, and supports writing internationalized code.

With the C++ 5.0 compiler in compatibility mode, you get classic iostreams, the same version supplied with the C++ 4.2 compiler. Any existing iostream code that works with the 4.2 compiler should work exactly the same way with the 5.0 compiler in compatibility mode.

In standard mode, you get standard iostreams by default. If you use the standard form of header names (without ".h"), you get the standard headers, with all declarations in namespace std.

Each of the standard headers is also provided in a form ending with ".h" that makes the header names available in the global namespace via using-declarations. These headers are a Sun extension, and code that depends on them might not be portable. These headers allow you to compile existing (simple) iostream code without having to change the code, even though standard iostreams are used instead of classic iostreams. For example, the following example compiles using standard iostream name streams.

 #include <iostream> int main() { std::cout << "Hello, world!" << std::endl; }

The following example, compiles with using classic iostream name forms.

 #include <iostream.h> int main() { cout << "Hello, world!" << endl; }

Not all classic iostream code is compatible with standard iostreams. If your classic iostream code does not compile, you must either modify your code, or use classic iostreams entirely.

To use classic iostreams in standard mode, use the compiler option library=iostream on the CC command line. When this option is used, a special directory is searched that contains the classic iostream header files, and the classic iostream runtime library is linked with your program. You must use this option on all compilations that make up your program as well as on the final link phase, or you will get inconsistent program results.


Note -

Mixing old and new forms of iostreams--including the standard input and output streams cin, cout, and cerr--in the same program can cause severe problems and is not recommended.