Hi Guys,
I was trying to learn creating headers. I just created a file Class.h and include iostream in the header instead of the .cpp file. When I tried to compile the .cpp file, I am unable to use cout.
Aren't all the headers included in a header file accesible by the .cpp file by including only the super header?
Yes. Tell me, what headers are included in your file "class.h"? I see zero headers included in your file "class.h"
I just created a file Class.h and include iostream in the header
No you didn't. Where in your header file have you written #include <iostream> ? Nowhere.
Somewhere, there has to be written #include <iostream>
if you want to include that header.
It can be in the cpp file, it can be in a header file that is included, it can be in a header file that's included by that header files header file, and so on.
Your code does not have #include <iostream>
in it, anywhere.
Not in your cpp file. Not in your header file. Your header file includes no other header files. It does not have #include <iostream>
written in it.