Consider this code:
int xx;
std::cin >> std::setfill('0') >> std::setw(4) >> xx;
When sending 12
to the standard input I am expecting the value of xx
to be 1200
and when sending 12345
I am expecting it to be 1234
.
However, it seems std::setfill
and std::setw
have no effect and I am getting 12
and 12345
respectively.
Is this a bug or it is according to the standard? Is there a good way to get the expected functionality?
Also note, when I change the type of xx
to be std::string
the std::setw
takes effect while std::setfill
still doesn't.
My compiler is gcc-7.0.1
.