flags

To alter formatting flags using a mask.

  fmtflags flags() const
  fmtflags flags(fmtflags)
  
Remarks

Use flags() when you would like to use a mask of several flags, or would like to save the current format configuration. The return value of flags() returns the current fmtflags. The overloaded flags(fmtflags) alters the format flags but will return the value prior to the flags being changed.

The fmtflags type before alterations.

See ios enumerators for a list of fmtflags.

SeeAlso:

setiosflags() and resetiosflags()

Listing: Example of flags() usage:
#include <iostream>
// showf() displays flag settings

void showf();

int main()

{

using namespace std;

   showf(); // show format flags

   cout << "press enter to continue" << endl;

   cin.get();

   cout.setf(ios::right|ios::showpoint|ios::fixed);

   showf();

   return 0;

}

// showf() displays flag settings

void showf()

{

using namespace std;

   char fflags[][12] = {

               "boolalpha",

               "dec",

               "fixed",

               "hex",

               "internal",

               "left",

               "oct",

               "right",

               "scientific",

               "showbase",

               "showpoint",

               "showpos",

               "skipws",

               "unitbuf",

               "uppercase"

   };

   long f = cout.flags();    // get flag settings

   cout.width(9); // for demonstration 

      // check each flag

   for(long i=1, j =0; i<=0x4000; i = i<<1, j++)

   {

      cout.width(10); // for demonstration

      if(i & f) 

         cout << fflags[j] << " is on \n";

      else 

         cout << fflags[j] << " is off \n";

   }

   cout << "\n";

}

Result:

  boolalpha   is off
  dec         is on
  fixed       is off
  hex         is off
  internal    is off
  left        is off
  oct         is off
  right       is off
  scientific  is off
  showbase    is off
  showpoint   is off
  showpos      is off
  skipws       is on
  unitbuf      is off
  uppercase   is off
  press enter to continue
  boolalpha is off
        dec is on
              hex is off
     internal is off
           left is off
            oct is off
         right is on
  scientific is off
     showbase is off
   showpoint is on
      showpos is off
        skipws is on
      unitbuf is off
  uppercase is off