Sunday, 8 September 2013

Formatting flags in ios class


What are formatting flags in ios class?

Ans: The ios class contains formatting flags that help users to format the stream data. Formatting
flags are a set of enum definitions. There are two types of formatting flags: 

  1. On/Off flags 
  2. Flags that work in-group  

The On/Off flags are turned on using the setf( ) function and are turned off using the unsetf( ) function. To set the On/Off flags, the one argument setf( ) function is used. The flags working in groups are set through the two-argument setf( ) function. For example, to left justify a  string we can set the flag as,

  1. cout.setf ( ios::left ) ;
  2. cout << "KICIT Nagpur" ; 

To remove the left justification for subsequent output we can say, 

                             cout.unsetf ( ios::left ) ; 

The flags that can be set/unset include skipws, showbase, showpoint, uppercase, showpos, unitbuf and stdio. The flags that work in a group can have only one of these flags set at a time.