I am really confused about how we use std libraries in the header. When to use which library. Is "using namespace std" and conio.h different..?? Or are they the same thing. And what is the difference between "iostream" and "iostream.h". These things are making me really confused.....
-
If you're confused, then make things simple: stop writing `using namespace std`. – Nicol Bolas Oct 19 '16 at 04:33
-
Where do you find this dark age stuff? – DeiDei Oct 19 '16 at 05:41
-
Possible duplicate of [
vs. – Oct 19 '16 at 07:25vs. "iostream.h"](http://stackoverflow.com/questions/214230/iostream-vs-iostream-h-vs-iostream-h)
2 Answers
std
is the namespace for the C++ standard library - for example,string
actually belongs to this namespace, so the full name forstring
isstd::string
.using namespace std
tells the compiler that we want to access the resources in this namespace - giving usglobal
, or direct access to thestring
it holds. Take a look at Pete's comment for more details.The C++ standard library contains many different packages that can be included by their headers, one of which is
<iostream>
, morestd
headers can be found here: http://www.cplusplus.com/reference/conio.h
looks like an older DOS-specific C header that is not popular anymore.iostream.h
was renamed toiostream
as a standard at some point: http://members.gamedev.net/sicrane/articles/iostream.html
Also see: Why is "using namespace std" considered bad practice?
Edits thanks to Pete!
-
1`using namespace std;` doesn't "tell the compiler which `string` we're using"; it tells the compiler to, essentially, treat **all** names that are defined in `std` as if they were also defined in the global namespace. You could define your own name `string` in the global namespace, and `using namespace std;` would then guarantee that whenever you referred to `string` it would be ambiguous. That aside, good answer. – Pete Becker Oct 19 '16 at 12:52
-
-
It just simply allows you to use the namespace std
, which is the namespace of most standard C++ header libraries. If you use it, you won't have to put the std::
prefix on accessing, for example, std::cout
or std::cin
, which would now be just cout
and cin
respectively.
For example:
// without using namespace std
#include <iostream>
int main() {
cout << "Hello World"; // error
std::cout << "Hello World"; // outputs Hello World
return 0;
}
Now with using namespace std
:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World"; // outputs Hello World
return 0;
}
conio.h
is a C++ library that contains functions such as getch()
and putch()
. iostream.h
is a pre-standard C++ library that was used before namespaces were introduced. iostream
is a standard library that contains objects such as cin
and cout
.

- 3,730
- 19
- 30