0

I have the following line: const int PI(acos(-1.00));

I am able to compile the program without errors even though I am not using cmath in the header, only stdafx.h, iostream and fstream.

Every website I look on acos is part of the cmath header.

When I cout PI I get 3.

What is the reason for acos working without cmath header?

Lukali
  • 343
  • 1
  • 4
  • 15
  • 1
    With this little information one can only *speculate*, but it seems possible that some of the header files your app uses include `cmath` in turn (maybe for some simple math like `sqrt` or `hypot`). – njuffa Jan 07 '18 at 19:03
  • There isn't much else really. The main is just declearing and intitalising 3 variables and returning 0. Its less than 12 lines of code total. – Lukali Jan 07 '18 at 19:20
  • 1
    Have you tried looking into [`stdafx.h`](https://stackoverflow.com/questions/4726155/whats-the-use-for-stdafx-h-in-visual-studio) to see what includes? BTW, if your entire program is less then 12 lines, you could post it in the question. – Bob__ Jan 07 '18 at 19:55
  • @Lukali What header files will be included in turn by the header files used by your app will depend on the tool chain, the OS platform, and any compilation switches passed to the compiler. – njuffa Jan 07 '18 at 20:07

1 Answers1

0

Visual studio includes cmath in iostream, which is why it works. Kind of disappointing, there is no information on the internet about how iostream can consist of chosen libraries of the compiler.

Lukali
  • 343
  • 1
  • 4
  • 15