use of namespace

for what purpose we use
using namespace std;
Last edited on
closed account (zb0S216C)
That line of code isn't correct. It should be using namespace std. The line you posted, is a preprocessor directive, not a statement.

using namespace std tells the compiler that you will be using the entire standard namespace. This makes all definitions in the standard namespace public, and available to use.

Wazzak
There's alot of members in the std namespace. For example cout. So without that line you would simply need to say std::cout.
C++ got a proteccion for the colisions with names, for example a funcion max() its so current and for this reason let you to define coleccions of names.

When you use this line using namespace std; you are loading all the collecion on std, and then you dont need to do std::cout <<.

This is dungerous becouse if you define a funcion with the name cout you can't have the certaing your program use your funcion, then you could do this:

1
2
3
namespace myCout{
        class cout;
}


And then you can call him: myCout::cout ......;

Topic archived. No new replies allowed.