1.

What Is The Purpose Of Ios::basefield In The Following Statement? cout.setf ( Ios::hex, Ios::basefield );

Answer»

This is an example of formatting flags that WORK in a group. There is a FLAG for each numbering system (base) like decimal, octal and hexadecimal. Collectively, these flags are referred to as BASEFIELD and are specified by ios::basefield flag. We can have only ONE of these flags on at a time. If we set the hex flag as setf ( ios::hex ) then we will set the hex bit but we won't clear the dec bit resulting in undefined behavior. The solution is to call setf( ) as setf ( ios::hex, ios::basefield ). This call first CLEARS all the bits and then sets the hex bit.

This is an example of formatting flags that work in a group. There is a flag for each numbering system (base) like decimal, octal and hexadecimal. Collectively, these flags are referred to as basefield and are specified by ios::basefield flag. We can have only one of these flags on at a time. If we set the hex flag as setf ( ios::hex ) then we will set the hex bit but we won't clear the dec bit resulting in undefined behavior. The solution is to call setf( ) as setf ( ios::hex, ios::basefield ). This call first clears all the bits and then sets the hex bit.



Discussion

No Comment Found