GNU Info

Info Node: (iostream-295.info)Manipulators

(iostream-295.info)Manipulators


Next: Extending Prev: Format Control Up: Ios
Enter node , (file) or (file)node

Changing stream properties using manipulators
---------------------------------------------

   For convenience, MANIPULATORS provide a way to change certain
properties of streams, or otherwise affect them, in the middle of
expressions involving `<<' or `>>'.  For example, you might write

     cout << "|" << setfill('*') << setw(5) << 234 << "|";

to produce `|**234|' as output.

 - Manipulator:  ws
     Skip whitespace.

 - Manipulator:  flush
     Flush an output stream.  For example, `cout << ... <<flush;' has
     the same effect as `cout << ...; cout.flush();'.

 - Manipulator:  endl
     Write an end of line character `\n', then flushes the output
     stream.

 - Manipulator:  ends
     Write `\0' (the string terminator character).

 - Manipulator:  setprecision (int SIGNIF)
     You can change the value of `ios::precision' in `<<' expressions
     with the manipulator `setprecision(SIGNIF)'; for example,

          cout << setprecision(2) << 4.567;

     prints `4.6'.  Requires `#include <iomanip.h>'.

 - Manipulator:  setw (int N)
     You can change the value of `ios::width' in `<<' expressions with
     the manipulator `setw(N)'; for example,

          cout << setw(5) << 234;

     prints `  234' with two leading blanks.  Requires `#include
     <iomanip.h>'.

 - Manipulator:  setbase (int BASE)
     Where BASE is one of `10' (decimal), `8' (octal), or `16'
     (hexadecimal), change the base value for numeric representations.
     Requires `#include <iomanip.h>'.

 - Manipulator:  dec
     Select decimal base; equivalent to `setbase(10)'.

 - Manipulator:  hex
     Select hexadecimal base; equivalent to `setbase(16)'.

 - Manipulator:  oct
     Select octal base; equivalent to `setbase(8)'.

 - Manipulator:  setfill (char PADDING)
     Set the padding character, in the same way as `ios::fill'.
     Requires `#include <iomanip.h>'.


automatically generated by info2www version 1.2.2.9