Home

unsetf

Unsetf is a member function of the C++ standard library’s I/O stream base class (std::ios_base) and all derived stream types. It clears the format flags currently set on a stream by unsetting the bits specified by its argument. The operation affects only the stream’s format state and does not modify other aspects of the stream.

Format flags are defined in std::ios_base::fmtflags and include both individual flags (such as boolalpha, showbase, showpoint,

Usage examples illustrate common patterns. For instance, to revert floating-point formatting after using fixed or scientific,

Unsetf is often used together with setf to switch between formats and then return to defaults. It

uppercase,
skipws,
etc.)
and
groups
known
as
basefield,
adjustfield,
and
floatfield.
Unsetf
takes
a
mask
of
type
fmtflags
and
clears
the
corresponding
bits
in
the
stream’s
format
state.
If
a
group
flag
is
supplied,
the
bits
within
that
group
are
cleared
accordingly.
Passing
a
zero
mask
has
no
effect.
you
can
write:
std::cout.unsetf(std::ios::floatfield);
This
clears
the
floatfield
bits
and
restores
default
floating-point
formatting.
To
remove
any
base-related
formatting,
you
might
call:
std::cout.unsetf(std::ios::basefield);
Clearing
show-related
or
other
individual
flags
can
be
done
by
unsetting
the
specific
flag,
such
as
std::cout.unsetf(std::ios::showpos).
is
declared
in
<ios>
and
is
available
on
all
standard
streams,
including
std::cin,
std::cout,
and
std::cerr.
See
also
setf,
std::ios_base::fmtflags,
and
the
ios_base
class.