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


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

 

The C++ I/O system is based on a hierarchy of classes. The I/O system is quite large. 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.

 

 

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