Is there a reason why the cout stream has the std :: ios_base :: skipws set flag?

cout has the std::ios_base::skipws and std::ios_base::dec flags set by default

You can verify this with the code:

 #include <iostream> #include <string> using namespace std; int main() { ios_base::fmtflags flags = cout.flags(); string sflags; if( flags & ios_base::skipws ) sflags += "skipws"; if( flags & ios_base::unitbuf ) sflags += sflags.empty() ? "unitbuf" : " unitbuf"; if( flags & ios_base::uppercase ) sflags += sflags.empty() ? "uppercase" : " uppercase"; if( flags & ios_base::showbase ) sflags += sflags.empty() ? "showbase" : " showbase"; if( flags & ios_base::showpoint ) sflags += sflags.empty() ? "showpoint" : " showpoint"; if( flags & ios_base::showpos ) sflags += sflags.empty() ? "showpos" : " showpos"; if( flags & ios_base::left ) sflags += sflags.empty() ? "left" : " left"; if( flags & ios_base::right ) sflags += sflags.empty() ? "right" : " right"; if( flags & ios_base::internal ) sflags += sflags.empty() ? "internal" : " internal"; if( flags & ios_base::dec ) sflags += sflags.empty() ? "dec" : " dec"; if( flags & ios_base::oct ) sflags += sflags.empty() ? "oct" : " oct"; if( flags & ios_base::hex ) sflags += sflags.empty() ? "hex" : " hex"; if( flags & ios_base::scientific ) sflags += sflags.empty() ? "scientific" : " scientific"; if( flags & ios_base::fixed ) sflags += sflags.empty() ? "fixed" : " fixed"; if( flags & ios_base::hexfloat ) sflags += sflags.empty() ? "hexfloat" : " hexfloat"; if( flags & ios_base::boolalpha ) sflags += sflags.empty() ? "boolalpha" : " boolalpha"; if( flags & ios_base::_Stdio ) sflags += sflags.empty() ? "_Stdio" : " _Stdio"; cout << "Standard flags from cout stream: " << sflags << endl; } 

Obviously, the flag std::ios_base::skipws not related to cout.

+4
source share
2 answers

Flags and their settings are inherited by default from std::ios_base (well, in fact, the settings are defined for std::basic_ios<cT, Traits> , the default values โ€‹โ€‹are defined in 27.5.5.2 [basic.ios.cons]), general base class of both input and output streams. Flags are split if the stream is inherited from both input and output streams. There are other flags that do not make much sense for either input or output streams.

+5
source

The skipws flag skipws set in all standard threads during initialization. Not only std::cout . This makes sense for std::cout as for any other thread. You can disable it with noskipws if you hate it so much.

+1
source

All Articles