I experienced this weird issue recently having to do with cout.setf(ios::fixed). Took me quite a while to track down the cause and thought I\'d ask here to learn more.
Because you told it to.
From setf documentation on cppreference.com:
scientific - generate floating point types using scientific notation, or hex notation if combined with fixed: see
std::scientific
fixed - generate floating point types using fixed notation, or hex notation if combined with scientific: seestd::fixed
So, when setting std::fixed
, you need to unset std::scientific
(which is what your unmasking of std::floatfield
does, because std::floatfield
is std::scientific|std::fixed|(std::scientific|std::fixed)|0
) to avoid the hex notation.