
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ ios_base fmtflags
Description
This type is used as its parameter and/or return value by the member functions flags, setf and unsetf.
Declaration
Following is the declaration for ios_base::fmtflags.
std::ios_base::fmtflags ff;
The values passed and retrieved by these functions can be any valid combination of the following member constants as shown below −
field | member constant | effect when set |
---|---|---|
independent flags | boolalpha | read/write bool elements as alphabetic strings (true and false ). |
showbase | write integral values preceded by their corresponding numeric base prefix. | |
showpoint | write floating-point values including always the decimal point. | |
showpos | write non-negative numerical values preceded by a plus sign (+). | |
skipws | skip leading whitespaces on certain input operations. | |
unitbuf | flush output after each inserting operation. | |
uppercase | write uppercase letters replacing lowercase letters in certain insertion operations. | |
numerical base (basefield) |
dec | read/write integral values using decimal base format. |
hex | read/write integral values using hexadecimal base format. | |
oct | read/write integral values using octal base format. | |
float format (floatfield) |
fixed | write floating point values in fixed-point notation. |
scientific | write floating-point values in scientific notation. | |
adjustment (adjustfield) |
internal | the output is padded to the field width by inserting fill characters at a specified internal point. |
left | the output is padded to the field width appending fill characters at the end. | |
right | the output is padded to the field width by inserting fill characters at the beginning. |
Three additional bitmask constants made of the combination of the values of each of the three groups of selective flags can also be used as shown below.
flag value | equivalent to |
---|---|
adjustfield | left | right | internal |
basefield | dec | oct | hex |
floatfield | scientific | fixed |
The values of these constants can be combined into a single fmtflags value using the OR bitwise operator (|).
Example
In below example is shown for ios_base::fmtflags.
#include <iostream> int main () { std::cout.setf (std::ios_base::hex , std::ios_base::basefield); std::cout.setf (std::ios_base::showbase); std::cout << 100 << '\n'; std::cout.setf (std::ios::hex , std::ios::basefield); std::cout.setf (std::ios::showbase); std::cout << 100 << '\n'; std::cout.setf (std::cout.hex , std::cout.basefield); std::cout.setf (std::cout.showbase); std::cout << 100 << '\n'; std::ios_base::fmtflags ff; ff = std::cout.flags(); ff &= ~std::cout.basefield; ff |= std::cout.hex; ff |= std::cout.showbase; std::cout.flags(ff); std::cout << 100 << '\n'; std::cout << std::hex << std::showbase << 100 << '\n'; return 0; }
Let us compile and run the above program, this will produce the following result −
0x64 0x64 0x64 0x64 0x64
ios.htm
Advertisements