Electron microscopy
 
Stream in DM and C++
- Practical Electron Microscopy and Database -
- An Online Book -
Microanalysis | EM Book                                                                                   http://www.globalsino.com/EM/        


=================================================================================

 

The most fundamental point to understand the C++ I/O system is that it operates on streams. A stream is a common, logical interface to the various devices which comprise the computer. A stream either produces or consumes information, and it is linked to a physical device by the C++ I/O system. All streams behave in the same manner, even if the actual physical devices that they are linked are different. Because all streams act the same, the same I/O functions and operators can in fact operate on virtually any type of device. For instance, the method that you use to write to the screen can be used to write to a USB file or to the printer.

In general, a stream is a logical interface to a file. As C++ defines the term "file", it can refer to any devices such as a disk file, the screen, the keyboard, a port, a file on tape, and so on. Although files are different in form and capabilities, all streams are actually the same. The advantage to this approach is that, to the programmer, one hardware device will look much like any other, namely, the stream provides a consistent interface. The stream is linked to a file through an open operation, and it is disassociated from a file through a close operation.

There are two types of streams:
         i) Text. A text stream is used with some characters. When a text stream is being used, then some character translations may take place. For instance, when the newline character is output, it may be converted into a carriage-return/linefeed sequence. Therefore, there might not be a one-to-one response between what is sent to the stream and what is written to the file.
         ii) Binary. A binary stream can be used with any type of data. In this case, no character translations will occur, and there is a one-to-one response between what is sent to the stream and what is actually contained in the file.

C++ contains some predefined streams that are automatically opened when the program begins execution; however, DM might not provide such accesses of predefined streams to DM users as listed in Table 1101a.

Table 1101a. Comparison of stream in DM and C++.
 
Function C++ DM
Availability to programers
Predefined streams
cin The stream is associated with standard input Yes No
cerr

The stream is associated with standard output. The difference between these two streams is that clog is buffered, but cerr is not. Therefore, any output sent to cerr is immediately output, but output to clog is written only when a buffer is full. cerr and clog are typically streams to which program debugging or error information is written.

clog
Wide (16-bit) character versions of standard streams
wcin These streams exist to support all languages, such as Chinese, that require large character sets. Yes No
wcout
wcerr
wclog
Template class hierarchies
basic_ios (e.g. ios_base)

This is the most commonly used class hierarchy. This is a high-level I/O class that provides formatting, error checking, and status information related to stream I/O. The ios_base, defines several non-template traits used by basic_ios. basic_ios is used as a base for several derived classes, including basic_istream, basic_ostream, and basic_iostream. These classes are used to create streams capable of input, output, and input/output, respectively.

Yes No
basic_streambuf

This class is derived from the low-level I/O class, and supplies the basic, low-level input and output operations, and provides the underlying support for the entire C++ I/O system. Unless you are doing advanced I/O programming,
this class is not directly needed.

Yes No

By default, the C++ standard streams are linked to the console, but they can also be redirected to other devices, files, or operating systems by a program. In programs, C++ provides support for its I/O system in <iostream>. In this header, a very complicated set of class hierarchies is specified that supports I/O operations. The I/O classes begin with a set of template classes, which defines the form of a class without fully specifying the data upon which it will operate. Once a template class has been defined, specific instances of a template class can then be created. As it relates to the I/O library, Standard C++ creates two specializations of the I/O template classes:
        i) One class for 8-bit characters,
        ii) One class for wide characters.

Table 1101b lists the mapping of template class names to their character-based versions.

Table 1101b. Template class names to their character-based versions in C++.
Template Class Character-Based Class Note
basic_streambuf streambuf  
basic_ios ios The ios class contains many member functions and variables that
control or monitor the fundamental operation of a stream. If <iostream> is included in your program, you will have access to this important class.
basic_istream istream  
basic_ostream ostream  
basic_iostream iostream  
basic_fstream fstream  
basic_ifstream ifstream  
basic_ofstream ofstream  

 

 

=================================================================================