Computer Science - Object Oriented Programming Using C++ - Discussion
Discussion Forum : Object Oriented Programming Using C++ - Section 1 (Q.No. 4)
4.
Format flags may be combined using
Discussion:
21 comments Page 1 of 3.
Sundar said:
1 decade ago
Let me explain in clear.
// Assume two 16-bit flags contains values as given below
intFlag1 = (00000000 10101010) In Binary.
intFlag2 = (00000010 01010101) In Binary.
// Now combine it with Bitwise-OR operator
intResult = intFlag1 | intFlag2 ;
// The combined result will be.
intResult = (00000010 11111111) In Binary.
Hope this will help you. Have a nice day!
// Assume two 16-bit flags contains values as given below
intFlag1 = (00000000 10101010) In Binary.
intFlag2 = (00000010 01010101) In Binary.
// Now combine it with Bitwise-OR operator
intResult = intFlag1 | intFlag2 ;
// The combined result will be.
intResult = (00000010 11111111) In Binary.
Hope this will help you. Have a nice day!
(2)
Supriya said:
3 years ago
3what is mean by format flag? Explain, please.
(1)
Shashank Singh said:
8 years ago
cout and cin contain several single-bit flags for format control. They are named in an enum in class ios as:
ios::skipws // skips whitspace on input
ios::left // left justification
ios::right // right justifiction
ios::internal // pads after sign or base character
ios::dec // decimal format for integers
ios::oct // octal format for integers
ios::hex // hex format for integers
ios::showbase // show the base character for octal or hex
ios::showpoint // show the decimal point for all floats
ios::uppercase // uppercase A-F for hex
ios::showpos // show +ve sign for numbers
ios::scientific // use exponential notation
ios::fixed // used oridnary decimal notation
ios::unitbuf // flush the buffer
These flags can be set with the member function setf. e.g.
cout.setf(ios::showpos);
They can be or'd together:
cout.setf(ios::showpos | ios::uppercase);
or some bits can be unset while one is being set:
cout.setf(ios::oct, ios::dec | ios::oct | ios::hex);
This sets the bit for oct, after unsetting the bits for oct, dec and hex, ensuring that only one of the bits is turned on.
unsetf turns bits off:
cout.unsetf(ios::showpos);
ios::skipws // skips whitspace on input
ios::left // left justification
ios::right // right justifiction
ios::internal // pads after sign or base character
ios::dec // decimal format for integers
ios::oct // octal format for integers
ios::hex // hex format for integers
ios::showbase // show the base character for octal or hex
ios::showpoint // show the decimal point for all floats
ios::uppercase // uppercase A-F for hex
ios::showpos // show +ve sign for numbers
ios::scientific // use exponential notation
ios::fixed // used oridnary decimal notation
ios::unitbuf // flush the buffer
These flags can be set with the member function setf. e.g.
cout.setf(ios::showpos);
They can be or'd together:
cout.setf(ios::showpos | ios::uppercase);
or some bits can be unset while one is being set:
cout.setf(ios::oct, ios::dec | ios::oct | ios::hex);
This sets the bit for oct, after unsetting the bits for oct, dec and hex, ensuring that only one of the bits is turned on.
unsetf turns bits off:
cout.unsetf(ios::showpos);
(1)
Jayasree said:
8 years ago
Please, be clear what are format flags?
(1)
Vinay said:
1 decade ago
Can anybody tell me what is format flag ?
(1)
G V said:
9 years ago
I didn't get this question? Please explain me.
Taruni said:
7 years ago
What is meant by format flag?
Aakash kr said:
7 years ago
Realy, I want to know what is format flag?
Tushar said:
8 years ago
Can anyone tell me what is format flags, and what is its use?
Johny said:
8 years ago
It is actually very beneficial. Thanks @Sunder.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers