How to set, clear and check the format flags in C++?

setf() function is used to set a format flag. It is a member function of ios class. Here’s the syntax of setf() function:

fmtflags setf(fmtflags flags);

For Example:


setf() function can also be overloaded. Syantax of overloading setf() function is given below:

fmtflags setf(fmtflags flagsa, fmtflags flagsb);

By overloading, only flags in flagsb are affected by flags in flagsa.

To clear a format flag unsetf() function is used. Syntax of unsetf() function:

void unsetf(fmtflags flags);

For Example:


To check the settings of format flags flag() function is used. Syntax of flag() function:

fmtflags flags( );

To set all format flags at once another format of flags() function is used:

fmtflags flags(fmtflags f);

Leave a Reply