Page 269 - DCAP404 _Object Oriented Programming
P. 269

Object-oriented Programming




                    Notes          This input will be read correctly and assigned to the character array name. Let us suppose the
                                   input is as follows:

                                   Object Oriented Programming

                                   In this case, the input will be terminated after reading the following 19 characters:
                                   Object Oriented Pro

                                   After reading the string, cin automatically adds the terminating null character to the character
                                   array.
                                   Remember, the two blank spaces contained in the string are also taken into account, i.e. between
                                   Objects and Oriented and Pro.
                                   We can also read strings using the operator >> as follows:
                                   cin >> name;

                                   But remember cin can read strings that do not contain white space. This means that cin can read
                                   just one word and not a series of words such as “Neeraj good”.





                                     Notes  Characters are extracted until either (n – 1) characters have been extracted or the
                                     delimiting character is  found (which  is delim  if this  parameter is  specified,  or  ‘\n’
                                     otherwise). The extraction also stops if the end of file is reached in the input sequence or if
                                     an error occurs during the input operation.

                                   Self Assessment


                                   Fill in the blanks:
                                   1.  ………………………. extracts characters from the  input sequence and stores them as a
                                       c-string into the array beginning at s.

                                   2.  The base of the ……………………….. library is the hierarchy of class templates.
                                   3.  A stream is an abstraction that represents a device on which input and …………………..
                                       operations are performed.

                                   4.  As part of the …………………… library, the header file <iostream> declares certain objects
                                       that are used to perform input and output operations on the standard input and output.
                                   5.  Streams are generally associated to a …………………… source or destination of characters.

                                   6.  Once a file stream is used to open a file, any input or output operation performed on that
                                       stream is physically reflected in the…………………. .
                                   7.  The  class  templates  in  this  class  hierarchy  have  the  same  name  as  their
                                       ………………………….. instantiations but with the prefix basic_.

                                   12.3 Unformatted I/O Operations

                                   Unformatted Input/Output is the most basic form of input/output. Unformatted input/output
                                   transfers the internal binary representation of the data directly between memory and the file.
                                   Formatted output converts the internal binary  representation of the data to ASCII characters
                                   which are written to the output file. Formatted input reads characters from the input file and



          262                               LOVELY PROFESSIONAL UNIVERSITY
   264   265   266   267   268   269   270   271   272   273   274