Header file confusion

I have been programming for quite sometime in C++ but lately i realized i have been doing it all wrong. I used header files like iostream.h and non standard functions like getch or clrscr.
Now im trying to learn the actual thing and i can't understand a few differences.

1st is the different header file iostream. I have read its not a file at all but a method. I'm not understanding this statement very well.
2nd is the namespace std. Where is this namespace defined.
3rd If the classes and functions are defined inside the namespace std then why is the header files required.

Last edited on
You were using very old stuff.

1: <iostream> is a header, and also a class
2: the standard namespace (std) is defined in the standard headers
3: a header is a file containing the declarations of some stuff, a namespace is a language features used to separate symbols coming from different libraries

See http://www.cplusplus.com/doc/tutorial/program_structure/
You may need to read all the tutorials to get used to ISO C++
See also http://www.cplusplus.com/reference/ for the current standard library
But the standard library is in the namespace std right.Are entire functions defined inside it.
Also i saw a program using the string class. it contained headers <iostream> and <string>. 'using namespace std' was used. Now if the std namespace is inside <iostream> class is it also inside the <string> class and are the two namespaces different. 'using namespace std' refers to which std ?

My questions might sound silly but im really very confused.
Last edited on
Each file uses namespace "std" { ... }. Since a namespace is just a name rather than a data type or structure or identifier, multiple files can use that namespace. There is no name clash because it is just a name.

I'm not sure if that explains it clearly enough, but I hope it helps a little.

I'd recommend reading http://www.cplusplus.com/doc/tutorial/namespaces/ to get a better understanding.
Last edited on
Well probably I'm not asking the question right.
What i'm saying is whether inside every header file is there a namespace called std.
And is withing that namespace all the functions are defined.
Last edited on
Either explicitly or through other header files via #include, the "std" namespace is in each header file in the standard library.

Within that namespace, all functions, classes and templates (and whatever else) belonging to the standard library are defined.
Last edited on
namespaces are extensible
My problem is solved. Thanks.
Topic archived. No new replies allowed.