parameterless manipulators that operate on output streams : cout « Development « C++ Tutorial






Manipulator            Purpose

boolalpha              Turns on boolalpha flag.

endl                   Outputs a newline.

ends                   Outputs a null.

dec                    Turns on dec flag. Turns off the hex and oct flags.

fixed                  Turns on fixed flag. Turns off the scientific flag.

flush                  Flushes the stream.

hex                    Turns on hex flag. Turns off the dec and oct flags.

internal               Turns on internal flag. Turns off the left and right flags.

left                   Turns on left flag. Turns off the right and internal flags.

noboolalpha            Turns off boolalpha flag.

noshowbase             Turns off showbase flag.

noshowpoint            Turns off showpoint flag.

noshowpos              Turns off showpos flag.

nounitbuf              Turns off unitbuf flag.

nouppercase            Turns off uppercase flag.

oct                    Turns on oct flag. Turns off the dec and hex flags.

right                  Turns on right flag. Turns off the left and internal flags.

scientific             Turns on scientific flag. Turns off the fixed flag.

showbase               Turns on showbase flag.

showpoint              Turns on showpoint flag.

showpos                Turns on showpos flag.

unitbuf                Turns on unitbuf flag.

uppercase              Turns on uppercase flag.
   

#include <iostream>
using namespace std; 
void showflags(void);

int main(void)
{
   showflags();
   cout.setf(ios::right | ios::showpoint | ios::fixed);
   showflags();
}

void showflags(void){
   long flag_set, i;
   int j;
   char flags[15][12] = {
      "skipws", "left", "right", "internal", "dec",
      "oct", "hex", "showbase", "showpoint", "uppercase",
      "showpos", "scientific", "fixed", "unitbuf",
   };

   flag_set = cout.flags();
   for (i=1, j=0; i<0x2000; i = i<<1, j++)
      if (i & flag_set)
         cout << flags[j] << " is on." << endl;
      else
         cout << flags[j] << " is off." << endl;
   cout << endl;
}








5.2.cout
5.2.1.parameterless manipulators that operate on output streams
5.2.2.To use a parameterized manipulator, you must include . It defines the following manipulators:
5.2.3.Using Manipulators to Format I/O
5.2.4.Use std::cout to output message to console
5.2.5.Use std::cout to output various data
5.2.6.Printing a line of text with multiple statements
5.2.7.Use std::endl to output a new line sign
5.2.8.cout: unsetf
5.2.9.Printing multiple lines of text with a single statement: use the \n
5.2.10.Output a pointer
5.2.11.Use function in cout statement
5.2.12.cout: setf()
5.2.13.cout: flags() and unsetf()
5.2.14.cout: width()
5.2.15.cout: precision()
5.2.16.cout: fill()
5.2.17.Using write().
5.2.18.An I/O manipulator: cout << setprecision(2)
5.2.19.An I/O manipulator: cout << setw(20)
5.2.20.use the setiosflags( ) manipulator to directly set the various format flags related to a stream.
5.2.21.cout: setiosflags()
5.2.22.Skip leading whitespace.
5.2.23.Scientific mode; don't show plus sign anymore
5.2.24.Fixed-point mode, show a '+' for positive nums, show 3 digits to the right of the decimal
5.2.25.setiosflags(ios::showpos); and setiosflags(ios::showbase);
5.2.26.ios::showpos | ios::showbase | ios::oct | ios::right
5.2.27.Set cout to output hex
5.2.28.Show default condition of format flags
5.2.29.cout.setf(ios::showpoint | ios::showpos, ios::showpoint);
5.2.30.Set ios::showpoint, ios::showpos for double pointer number
5.2.31.OR together two or more flags
5.2.32.unset flag one by one
5.2.33.cout boolalpha: cause bool values to display as true or false
5.2.34.Demonstrating the flags member function
5.2.35.Using showpoint to control the printing of trailing zeros anddecimal points for doubles
5.2.36.Demonstrating left justification and right justification
5.2.37.Printing an integer with internal spacing and plus sign
5.2.38.Using stream-manipulator showbase to show number base
5.2.39.Stream-manipulator uppercase.
5.2.40.Demonstrating stream-manipulators boolalpha and noboolalpha.
5.2.41.Controlling precision of floating-point values.
5.2.42.Check cout flags