Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Upgrading Issues
Collapse the table of content
Expand the table of content

Standard C++ Library Changes: Upgrading Issues 

The following topic discuss difficulties you may encounter with an earlier application and the new run-time libraries.

Differences in iostream Implementation

The old iostream library was removed beginning in Visual C++ .NET 2003.

The main difference between the Standard C++ Library and previous run-time libraries is in the iostream library. Details of the iostream implementation have changed, and it may be necessary to rewrite parts of your code that use iostream if you want to link with the Standard C++ Library.

You will have to remove any old iostream headers (fstream.h, iomanip.h, ios.h, iostream.h, istream.h, ostream.h, streamb.h, and strstrea.h) you have included in your code and add one or more of the new Standard C++ iostream headers (<fstream>, <iomanip>, <ios>, <iosfwd>, <iostream>, <istream>, <ostream>, <sstream>, <streambuf>, and <strstream>, all without the .h extension).

The following list describes behavior in the new Standard C++ iostream library that differs from behavior in the old iostream library.

In the new Standard C++ iostream library:

  • open functions do not take a third parameter (the protection parameter).

  • You cannot create streams from file handles.

  • With a couple of exceptions, all names in the new Standard C++ Library are in the std namespace. See Using C++ Library Headers for more information.

  • You cannot open ofstream objects with the ios::out flag alone. The ios::out flag must be combined with another ios enumerator in a logical OR; for example, with ios::in or ios::app.

  • ios::good no longer returns a nonzero value after reaching the end-of-file because the eofbit state is set.

  • ios::setf(_IFlags) should not be used with a flag value of ios::dec, ios::oct, or ios::hex unless you know that none of the base flags are currently set. The formatted input/output functions and operators assume that only one base is set. Instead, use ios_base. For example, setf( ios_base::oct, ios_base::basefield ) clears all base information and sets the base to octal.

  • ios::unsetf returns void instead of the previous value.

  • istream::get( char& _Rch ) does not assign to Rch if there is an error.

  • istream::get( char* _Pch, int _Ncount, char _Delim ) is different in three ways:

    • When nothing is read, failbit is set.

    • An eos is always stored after characters extracted (this happens regardless of the outcome).

    • A value of -1 for _Ncount is an error.

  • istream::seekg with an invalid parameter does not set failbit.

  • The return type streampos is a class with overloaded operators. In functions that return a streampos value (such as istream::tellg, ostream::tellp, strstreambuf::seekoff, and strstreambuf::seekpos), you should cast the return value to the type required: streamoff, fpos_t, or mbstate_t.

  • The first function parameter (_Falloc) in strstreambuf::strstreambuf( _Falloc, _Ffree ) takes a size_t argument, not a long.

In addition to the above changes, the following functions, constants, and enumerators that are elements of the old iostream library are not elements of the new iostream library:

  • attach member function of filebuf, fstream ifstream, and ofstream

  • fd member function of filebuf, fstream ifstream, and ofstream

  • filebuf::openprot

  • filebuf::setmode

  • ios::bitalloc

  • ios::nocreate

  • ios::noreplace

  • ios::sync_with_stdio

  • streambuf::out_waiting

  • streambuf::setbuf (use rdbuf -> pubsetbuf for the same behavior)

Earlier Projects Built with No Default Libraries

You can build a project without default libraries by selecting /NODEFAULTLIB. If your previous project was built with no default libraries and you want to make iostream calls, you must name one of the new Standard C++ run-time libraries (Libcp.lib, Libcpmt.lib, Msvcprt.lib, and so on) or one of the old iostream run-time libraries (Libci.lib, Libcimt.lib, Msvcirt.lib, and so on) in order to link with the proper library.

In previous Visual C++ versions (4.1 and earlier), the run-time library names were Libc.lib, Libcmt.lib, and Msvcrt.lib. These libraries included the old iostream library. The old iostream library has now been removed from these libraries. If you do not choose to ignore default libraries and you include old iostream header files in your code, the old iostream run-time libraries (Libci.lib, Libcimt.lib, Msvcirt.lib, and so on) are linked by default. However, if you have chosen to ignore default libraries and have manually added one of the early run-time libraries, your iostream calls will now break.

C++ Exception Handling Must Be Enabled for the Standard C++ Library

Any file that uses the Standard C++ Library must be compiled with C++ exception handling enabled. For more information, see /GX.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft