Page 271 - DCAP404 _Object Oriented Programming
P. 271

Object-oriented Programming




                    Notes          Manipulators are special functions that can be included in these statements to alter the format
                                   parameters of a stream. The table given below shows some important manipulator functions
                                   that are frequently used. To access these manipulators, the file iomanip.h should be included in
                                   the program.

                                                 Manipulators                      Equivalent ios function
                                     setw()                               width()
                                     setprecision()                       precision()
                                     Setfill()                            fill()
                                     setiosflags()                        setf()
                                     resetiosflags()                      unsetf()

                                   In addition to these functions supported by the C++ library, we can create our own manipulator
                                   functions to provide any special output formats.




                                      Task  Analyze the difference between the advantages of unformatted and formatted I/O.

                                   Self Assessment

                                   Fill in the blanks:

                                   8.  ……………………….. input/output transfers the internal binary representation of the data
                                       directly between memory and the file.
                                   9.  Unformatted data files can only be moved easily to and from computers that share the
                                       same internal………………………...
                                   10.  Formatted input/output is more computationally ………………………. than unformatted
                                       input/output.
                                   11.  The …………………… class contains a large number of member functions that could be
                                       used to format the output in a number of ways.
                                   12.  …………………………. are special functions that can be included in these statements to
                                       alter the format parameters of a stream.

                                   12.4 Managing Output with Manipulators


                                   These operators are used to format the data display. The commonly used manipulators are endl
                                   and setw.
                                   1.  endl manipulator when used causes a linefeed to be inserted. For example,

                                       cout      <<“m=”  <<m  <<endl
                                          <<“n=”  <<n  <<endl
                                          <<“p=”  <<p  <<endl;
                                       would cause the output as:
                                       Assuming the values of variables as 2597, 14 and 175.
                                       m = 2597




          264                               LOVELY PROFESSIONAL UNIVERSITY
   266   267   268   269   270   271   272   273   274   275   276