My program is working, but I'm not sure why?

I am able to run my program, using a math function and a limits function. But I havn't included their header files?

1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main()
{
	std::cout << sqrt(5.5);

	std::cout << "\nPress ENTER to exit";
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	return 0;
}


Last edited on
You probably just hit "run" and din't rebuild it so you are using the last build that had the includes. Or maybe you are using a precompiled header?
Hi.

I'm using VS2012 and in the project properties it says "Not using precompiled headers". Also this is the first build, I never included them.

EDIT: Just to double check, I rebuilt and seems to be working still. This is confusing :)

Thanks, Jack.
Last edited on
Compilers are allowed to include headers within headers. However, it is not recommended that you rely on the behavior of your particular compiler, as it may vary within different versions of the same compiler or even with different compiler settings and the same version. And, it will certainly vary for different compilers. So to be portable, use the required headers.

TL; DR: Use the correct headers. That it works how you expect it to is coincidence.
Hello,

I think most compilers are configured by default to link our programs with the standard library even if we dont include the header files.

I've tested that with C and C++.

Not sure.I'll investigate more.

My sources :

http://www.it-book-recommendations.com/departments/programming%20languages/c_c++/index.html
Topic archived. No new replies allowed.