Using name space std

Why we use using namespace????

what is mean of std???/
The C++ standard library object and algorithms are placed in the std namespace.

It's more a matter of fact, rather than something that has an explanation.
I have another question!!!
If we have a statement 2%10 then the output is 2 why isn't 0????
Any rule defining this problem????
The % operator returns the remainder of the division calculation.

In this instance 10 goes in to 2 zero times and has a remainder 2.

If you did 5 % 2, the value would be 1 as 2 goes in to 5 2 times and has a remainder of 1.

WIth regards to your initial question:

std is a class which is contained in the C++ libraries and cout is contained within that class. [I have chosen cout for this example but the same principal applies to everything that uses the std class]

Therefore, every time you want to use cout you need to write:


By including "using namespace std" you can now just write

cout and don't have to add std:: everytime you use cout.
Just a note.
Avoid using using namespace namespace_name use using namespace_name::symbol instead for frequently used symbols.

for example if you use cout throughout a cpp file then have using std::cout; after the includes
Topic archived. No new replies allowed.