On Saturday, 4 April 2015 01:58:56 UTC+3, Stefan Ram wrote:
>
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> >#include <iostream> // ::std::cout
> >#include <ostream> // ::std::ostream (<<)
> >#include <iomanip> // ::std::setw, ::std::setprecision
> >#include <ios> // ::std::fixed
> >#include <cmath> // ::std::atan2
> >#include <cstdlib> // ::std::printf
> >
> >int main()
> >{ constexpr double pi = 4 * atan2( 1, 1 );
> > ::std::cout << ::std::fixed << ::std::setw( 6 )<<
> > ::std::setprecision( 1 ) << pi << "\n";
> > ::std::printf( "%6.1f\n", pi ); }
>
> Recently, Herb Sutter compared a piece of Python to
> an equivalent piece of C++ and said that the C++ was
> not very much longer. I just now become aware of the
> fact that he omitted the »#include«s from the C++ code!
Including <iostream> is guaranteed to include also <ios>,
<streambuf>, <istream>, <ostream> and <iosfwd>.
So you actually needed <iostream> and <iomanip>
>
> Also, he compared Java and Python as they are now with
> C++ as it will possibly be when C++ 17 is published
> (he used concepts in the C++ code).
>
> Also, what is really annoying with those manipulators:
> Some of them change the stream just for the next output
> operation, while others change the stream forever, and
> I am not aware of a rule to derive which of the manipulators
> only modify a stream for the next output operation.
>
> And then, some need »#include <iomanip>« and some seem to
> need »#include <ios>«, and I am also not aware of a rule
> to determine which require which header.
>
> In the case of »printf« the »%6.1f« /always/ only refers to
> a single output operation and the include /always/ is
> »#include <cstdio>«.
Yeah, using the C++ I/O manipulators a lot is somewhat annoying.
> Concepts really would blend good together with a C++doc
> system, so that we have a standard to express semantic
> requirements for the operations of a concept. Like, for
> example, a kind of Doxygen becoming part of ISO C++.
We will see. I suspect we maybe hope too lot from those long
promised things like concepts, reflection or modules.