Subject: Re: IOStreams behavior definition
From: Philip Prindeville (philipp_subx_at_[hidden])
Date: 2020-06-30 16:46:22
> On Jun 30, 2020, at 11:46 AM, Ronan Keryell <rkeryell_at_[hidden]> wrote:
>> 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?
> We cannot clarify all the websites talking about C++ on the Internet. :-)
> This mailing-list is about discussing the ISO C++ standard itself more
> than answering end-user questions. Perhaps places like
> https://stackoverflow.com/questions/tagged/c%2b%2b are more responsive
> for your question.
> Personally I find http://www.cplusplus.com quite obsolete compared to
> https://en.cppreference.com/w/ in the same domain. Perhaps it might
> answer your question if you dive into it.
It claims that:
When used in an expression out << setw(n) or in >> setw(n), sets the width parameter of the stream out or in to exactly n.
But that doesn't seem to be the case for integer extractors. I think someone else called out that only std::string honors setw() on input, which seems arbitrary and violates the "Principle of Least Astonishment", or at least the expectation that object models & patterns get used uniformly and consistently.
Manages the minimum number of characters to generate on certain output operations and the maximum number of characters to generate on certain input operations.
By contrast mentions ONLY output, and omits any mention of input but then goes on to say
Some I/O functions call width(0) before returning, see std::setw (this results in this field having effect on the next I/O function only, and not on any subsequent I/O)
The exact effects this modifier has on the input and output vary between the individual I/O functions and are described at each operator<< and operator>> overload page individually.
And yes, on that note of "discussing the ISO C++ standard itself" I find guidance on uniformly implementing setw() on input streams to be lacking. Maybe it's worth fleshing out?
STD-DISCUSSION list run by herb.sutter at gmail.com
Older Archives on Google Groups