Yet another take on "using namespace std;"

Pages: 12
1
2
3
4
5
6
7
#include <iostream>
// #include <cmath>

int main()
{
   std::cout << "The square root of 4 is ... " << std::sqrt( 4.0 ) << '\n';
}

MinGW-W64 8.1.0 won't compile this, "error: 'sqrt' is not a member of 'std'"

VS2019 happily chugs away without an error or warning.

One compiler appears to implicitly include other headers, the other doesn't.
> One compiler appears to implicitly include other headers, the other doesn't.

The standard allows it:
Conforming implementations: Headers: A C++ header may include other C++ headers.
It makes it hard to know what to include at times when switching compilers without a lot of trial and error.

At the very least including what could be unnecessary headers won't have a huge impact on compile time or run time performance.

A committee designing a horse would create a giraffe. Or worse.
> It makes it hard to know what to include at times when switching compilers

No; the standard headers that must be included (in a potable program) before a library facility is used is specified by the standard.
Topic archived. No new replies allowed.
Pages: 12