Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using namespace std and library

Tags:

c++

Why we need both the "header file" and the using namespace tag for the any library function to get executed properly. For example cout will not work unless we use iostream. Also it will not work unless we use "using namespace std". My question is why do we need combination of both using namespace std as well as #include <iostream> for cout to execute successfully?

like image 679
Unbreakable Avatar asked Dec 21 '14 05:12

Unbreakable


1 Answers

Including a library header makes the library feature visible to your program code. Without that, your program has no idea that the library even exists. This is the part that is necessary.

Writing using namespace std simply allows you to write cout rather than the full name which is std::cout. It's a convenience, that's all.

like image 86
Lightness Races in Orbit Avatar answered Sep 19 '22 12:09

Lightness Races in Orbit