Sunday 8 September 2013

Tags

What is the purpose of ios::basefield in the following statement?
cout.setf ( ios::hex, ios::basefield ) ;  


Ans: 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.



EmoticonEmoticon