Page 306 - DCAP404 _Object Oriented Programming
P. 306

Unit 13: Working with Files




             After studying the Indian IT sector and also the prevailing politics here, the author grimly  Notes
             predicts that the sector is likely to remain divorced from the rest of Indian society and be
             focused on export markets, thus reinforcing much of  the inequality in Indian  society,
             which in turn feeds back into Indian domestic politics and maintains the status quo. He,
             however, feels that a virtuous cycle can possibly see a strong reform programme creating
             the conditions for a broad-based innovation system.
             Recommended read.

             dmurali@thehindu.co.in
             Tailpiece
             “After the management decided to ban all social networking within the office, we found
             a dramatic increase in…”
             “Productivity?”
             “No, absenteeism”

          13.8 Summary


              Fields in C++ are interpreted as a sequence of or stream of bytes stored on some storage
               media’. Member functions of these or base classes are used to perform I/O operations.
              The read( ) and write( ) functions work in binary mode. The ifstream class is used for input,
               ofstream for output and itstream for both input and output.
              A data of a file is stored in the form of readable and printable characters then the file is
               known as text file. A file contains non-readable characters in binary code then the file is
               called binary file.
              The function get( ) read and write data respectively. The read( ) and write( ) function read
               and write block of binary data. The close( ) function close the stream.
              The eof( ) functions determines end-of-file by returning true otherwise false.
              C++ treats each source of input and output uniformly. The abstraction of a data source and
               data sink is what is termed as stream. A stream is a data abstraction for input/output of
               data to and fro the program.

              C++ library provides prefabricated classes for data streaming activities. In C++, the file
               stream classes are designed with the idea that a file should simply be viewed as a stream
               or array or sequence of bytes.
              A file normally remains in a closed state on a secondary storage device until explicitly
               opened by a program.

              The << operator is a predefined operator. This line puts the text in the file or an output
               stream.
              C++ offers a host of different opening modes for the input file each offering different types
               of reading control over the opened file. The file opening modes have been implemented
               in C++ as enumerated type called ios.

              During a program execution structures are not created on a disk rather they are created in
               the memo.
              Binary files provide a better way of storing structures into a data file on the disk using
               read() and write() functions. Classes are also created in the memory just like structures and
               hence are lost at the termination of the program that created them.



                                           LOVELY PROFESSIONAL UNIVERSITY                                   299
   301   302   303   304   305   306   307   308   309   310   311