Skip to content. Skip to navigation

ICTP Portal

Sections
You are here: Home Manuals on-line PGI Compiler pgC_lib stdlibug 2.14 Differences between Standard and Traditional Iostreams
Personal tools
Document Actions

2.14 Differences between Standard and Traditional Iostreams



Click on the banner to return to the user guide home page.

2.14 Differences between Standard and Traditional Iostreams

[45]

The standard iostreams facility differs substantially from the traditional iostreams. This section briefly describes the main differences.

2.14.1 The Character Type

In the past, you may already have used iostreams--the traditional iostreams. The iostreams included in the Standard C++ Library are mostly compatible, yet slightly different from what you know. The most apparent change is that the new iostream classes are templates, taking the type of the character as a template parameter.

The traditional iostreams were of limited use. They could handle only byte streams; in other words, they read files byte per byte, and worked internally with a buffer of bytes. They had problems with languages that have alphabets containing thousands of characters. These alphabets are encoded as multibytes for storage on external devices like files, and represented as wide characters internally. They required a code conversion with each input and output.

The new templatized iostreams can handle large alphabets. These iostreams can be instantiated for one-byte skinny characters of type char, and for wide characters of type wchar_t. In fact, you can instantiate iostream classes for any user-defined character type. Section 2.13 describes in detail how this can be done.

2.14.2 Internationalization

Another new feature of the standard iostreams is internationalization. Traditional iostreams were incapable of adjusting to local conventions. Output of numerical items was always done following the US English conventions for number formatting. The new iostreams are internationalized to allow for local conventions. They use the standard locales described in the section on locales.

2.14.3 File Streams

2.14.3.1 Connecting Files and Streams

The traditional iostreams supported a file stream constructor, taking a file descriptor that allowed connection of a file stream to an already open file. This is no longer available in the standard iostreams.

The functions attach() and detach() do not exist anymore.

2.14.3.2 The File Buffer

Due to changes in the iostream architecture, the file buffer is now contained as a data member in the file stream classes. In some old implementations, the buffer was inherited from a base class called fstreambase.

The old file streams had a destructor; the new file streams don't need one. Flushing the buffer and closing the file is now done by the file buffer's destructor.

2.14.4 String Streams

Output string streams are always dynamic. The str() function does not have the functionality of freezing the string stream anymore. Instead, the string provided through str() is copied into the internal buffer; it is not used as the internal buffer. Accordingly, the string returned through str() is always a copy of the internal buffer.

If you need to influence a string stream's internal buffering, you must do it through pubsetbuf().

The classes strstream, istrstream, ostrstream, and strstreambuf are deprecated features in the standard iostreams. They are still provided by this implementation of the standard iostreams, but will be omitted in the future.

2.14.5 Streams with Assign

The classes ostream_withassign, istream_withassign, and iostream_withassign do not exist in the standard iostreams anymore. You can only assign the data components of a stream to another stream. This is done through the functions copyfmt() and rdbuf() in class basic_ios.


©Copyright 1996, Rogue Wave Software, Inc.

Weather
No information available
 

Powered by Plone This site conforms to the following standards: