Manipulators are special helper functions that help controlling input and output streams using operator >>
or operator <<
.
They all can be included by #include <iomanip>
.
Manipulators can be used in other way. For example:
os.width(n);
equals to os << std::setw(n);
is.width(n);
equals to is >> std::setw(n);
os.precision(n);
equals to os << std::setprecision(n);
is.precision(n);
equals to is >> std::setprecision(n);
os.setfill(c);
equals to os << std::setfill(c);
str >> std::setbase(base);
or str << std::setbase(base);
equals tostr.setf(base == 8 ? std::ios_base::oct :
base == 10 ? std::ios_base::dec :
base == 16 ? std::ios_base::hex :
std::ios_base::fmtflags(0),
std::ios_base::basefield);
os.setf(std::ios_base::flag);
equals to os << std::flag;
is.setf(std::ios_base::flag);
equals to is >> std::flag;
os.unsetf(std::ios_base::flag);
equals to os << std::no ## flag;
is.unsetf(std::ios_base::flag);
equals to is >> std::no ## flag;
flag
s: boolalpha
, showbase
, showpoint
, showpos
, skipws
, uppercase
.std::ios_base::basefield
.flag
s: dec
, hex
and oct
:os.setf(std::ios_base::flag, std::ios_base::basefield);
equals to os << std::flag;
is.setf(std::ios_base::flag, std::ios_base::basefield);
equals to is >> std::flag;
str.unsetf(std::ios_base::flag, std::ios_base::basefield);
equals to str.setf(std::ios_base::fmtflags(0), std::ios_base::basefield);
std::ios_base::adjustfield
.flag
s: left
, right
and internal
:os.setf(std::ios_base::flag, std::ios_base::adjustfield);
equals to os << std::flag;
is.setf(std::ios_base::flag, std::ios_base::adjustfield);
equals to is >> std::flag;
str.unsetf(std::ios_base::flag, std::ios_base::adjustfield);
equals to str.setf(std::ios_base::fmtflags(0), std::ios_base::adjustfield);
( 1 ) If flag of corresponding field previously set have already unset by unsetf
.
( 2 ) If flag
is set.
std::ios_base::floatfield
.os.setf(std::ios_base::flag, std::ios_base::floatfield);
equals to os << std::flag;
is.setf(std::ios_base::flag, std::ios_base::floatfield);
equals to is >> std::flag;
flag
s: fixed
and scientific
.os.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield);
equals to os << std::defaultfloat;
is.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield);
equals to is >> std::defaultfloat;
str.setf(std::ios_base::fmtflags(0), std::ios_base::flag);
equals to str.unsetf(std::ios_base::flag)
flag
s: basefield
, adjustfield
, floatfield
.os.setf(mask)
equals to os << setiosflags(mask);
is.setf(mask)
equals to is >> setiosflags(mask);
os.unsetf(mask)
equals to os << resetiosflags(mask);
is.unsetf(mask)
equals to is >> resetiosflags(mask);
mask
of std::ios_base::fmtflags
type.