Because streams are by default configured to skip whitespace, therefore, use
noskipws(strm);
Standard:
basic_ios constructors
explicit basic_ios(basic_streambuf<charT,traits>* sb);
Effects: Constructs an object of class basic_ios, assigning initial values to its member objects by calling
init(sb).
basic_ios();
Effects: Constructs an object of class
basic_ios
(27.5.2.7) leaving its member objects uninitialized. The object shall be initialized by calling itsinit
member function. If it is destroyed before it has been initialized the behavior is undefined.[...]
void init(basic_streambuf<charT,traits>* sb);
Postconditions: The postconditions of this function are indicated in Table 118.
+----------+-------------+ | ... | ... | | flags() | skipws|dec | | ... | ... | +----------+-------------+ (Table 118)