Subject: IOStreams behavior definition
From: Philip Prindeville (philipp_subx_at_[hidden])
Date: 2020-06-30 11:35:00
Iâm trying to figure out what the appropriate behavior of std::setw() and std::ios_base::width() should be on a istream. It doesnât seem to be well defined.
If I have:
unsigned u1, u2;
is >> setw(2) >> u1 >> u2;
cout << u1 << â â << u2 << endl;
Iâd expect the output to be â1 23\nâ with â4â being the next character on the input stream.
Not the case.
g++ and clang++ both try to consume all available digits into the first argument regardless of width, even overflowing if there are too many digits.
In short, thereâs no way to do columnar input if there are no delimiter characters between numbers.
Youâd thing this would be a fairly common/obvious usage scenario but it doesnât seem to be well defined in the IOStreams specification.
Refers to both input and output streams but only describes output behavior concretely.
Its homologue width() on the other hand makes no mention of input at all.
Can some clarity be shed on this?
STD-DISCUSSION list run by herb.sutter at gmail.com
Older Archives on Google Groups