std::ios_base::fmtflags(3)
π NAME π
std::ios_base::fmtflags β std::ios_base::fmtflags
okay bestie, this is the std::ios_base::fmtflags(3) page from the C++ Standard Libary, and we're folding that manual-name energy in right here near the top. no cap, we're about to get into formatting flags.
β¨ Synopsis β¨
here's the exact type vibe:
typedef /*implementation defined*/ fmtflags;
static constexpr fmtflags dec = /*implementation defined*/
static constexpr fmtflags oct = /*implementation defined*/
static constexpr fmtflags hex = /*implementation defined*/
static constexpr fmtflags basefield = dec | oct | hex;
static constexpr fmtflags left = /*implementation defined*/
static constexpr fmtflags right = /*implementation defined*/
static constexpr fmtflags internal = /*implementation defined*/
static constexpr fmtflags adjustfield = left | right | internal;
static constexpr fmtflags scientific = /*implementation defined*/
static constexpr fmtflags fixed = /*implementation defined*/
static constexpr fmtflags floatfield = scientific | fixed;
static constexpr fmtflags boolalpha = /*implementation defined*/
static constexpr fmtflags showbase = /*implementation defined*/
static constexpr fmtflags showpoint = /*implementation defined*/
static constexpr fmtflags showpos = /*implementation defined*/
static constexpr fmtflags skipws = /*implementation defined*/
static constexpr fmtflags unitbuf = /*implementation defined*/
static constexpr fmtflags uppercase = /*implementation defined*/
So this specifies the available formatting flags. It is a BitmaskType. The following constants are defined:
decβ use decimal base for integer I/O: seestd::decoctβ use octal base for integer I/O: seestd::octhexβ use hexadecimal base for integer I/O: seestd::hexbasefieldβdec | oct | hex. Useful for masking operationsleftβ left adjustment (adds fill characters to the right): seestd::leftrightβ right adjustment (adds fill characters to the left): seestd::rightinternalβ internal adjustment (adds fill characters to the internal designated point): seestd::internaladjustfieldβleft | right | internal. Useful for masking operationsscientificβ generate floating point types using scientific notation, or hex notation if combined withfixed: seestd::scientificfixedβ generate floating point types using fixed notation, or hex notation if combined withscientific: seestd::fixedfloatfieldβscientific | fixed. Useful for masking operationsboolalphaβ insert and extractbooltype in alphanumeric format: seestd::boolalphashowbaseβ generate a prefix indicating the numeric base for integer output, require the currency indicator in monetary I/O: seestd::showbaseshowpointβ generate a decimal-point character unconditionally for floating-point number output: seestd::showpointshowposβ generate a+character for non-negative numeric output: seestd::showposskipwsβ skip leading whitespace before certain input operations: seestd::skipwsunitbufβ flush the output after each output operation: seestd::unitbufuppercaseβ replace certain lowercase letters with their uppercase equivalents in certain output operations: seestd::uppercase
πΈ Example πΈ
The following example shows several different ways to print the same result.
// Run this code
#include <iostream>
int main()
{
const int num = 150;
// using fmtflags as class member constants:
std::cout.setf(std::ios_base::hex, std::ios_base::basefield);
std::cout.setf(std::ios_base::showbase);
std::cout << num << '\n';
// using fmtflags as inherited class member constants:
std::cout.setf (std::ios::hex, std::ios::basefield);
std::cout.setf (std::ios::showbase);
std::cout << num << '\n';
// using fmtflags as object member constants:
std::cout.setf(std::cout.hex, std::cout.basefield);
std::cout.setf(std::cout.showbase);
std::cout << num << '\n';
// using fmtflags as a type:
std::ios_base::fmtflags ff;
ff = std::cout.flags();
ff &= ~std::cout.basefield; // unset basefield bits
ff |= std::cout.hex; // set hex
ff |= std::cout.showbase; // set showbase
std::cout.flags(ff);
std::cout << num << '\n';
// not using fmtflags, but using manipulators:
std::cout << std::hex << std::showbase << num << '\n';
}
π Output π
0x96
0x96
0x96
0x96
0x96
π¦ See also π¦
flagsβ manages format flags(public member function)setfβ sets specific format flag(public member function)unsetfβ clears specific format flag(public member function)setbaseβ changes the base used for integer I/O(function)setfillβ changes the fill character(function template)fixedscientifichexfloatβ changes formatting used for floating-point I/O(function)(C++11)defaultfloatβ(function)(C++11)showbaseβ controls whether prefix is used to indicate numeric basenoshowbaseβ(function)boolalphaβ switches between textual and numeric representation of booleansnoboolalphaβ(function)showposβ controls whether the+sign used with non-negative numbersnoshowposβ(function)showpointβ controls whether decimal point is always included in floating-point representationnoshowpointβ(function)unitbufβ controls whether output is flushed after each operationnounitbufβ(function)skipwsβ controls whether leading whitespace is skipped on inputnoskipwsβ(function)uppercaseβ controls whether uppercase characters are used with some output formatsnouppercaseβ(function)
made with π and zero cap: source http://cppreference.com β’ version/date 2024.06.10 β that's the footer vibe, periodt. π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms