Inconsistent <iomanip> behavior

I have the following code

cout << setfill('0') << setw(4) << hex << 100 << 100 << std::endl;

      

Output:

006464

      

If I want every number with a width of 4 I have to use

out << setfill('0') << setw(4) << hex << 100 << sew(4) << 100 << std::endl;

      

But if I want to print every number with hex and setfill ('0'), I only need to set setfill ('0') and std :: hex once.

Will C ++ design this on purpose? what is his intention?

+3


source to share


1 answer


Yes, this is on purpose. Stream operations are internally overflowed by dropping the field width specified by the standard. I think there is no good answer as to why.



+2


source







All Articles