+ 16
[DUPLICATE] Using Namespace Std
What is the use of the code "using Namespace Std"??
8 Answers
+ 30
A library is like a set of rules and shortcuts. If you don't use the standard library (using namespace std), coding would be a bit more tedious for most.
For example, if you did not include the library, and you wrote a line of code like...
cout<<"hello world"<<endl;
... you would get an error because your compiler doesn't recognize cout/endl. You have to specify that it's from the standard library, like this ...
std::cout<<"hello world"<<std::endl;
... but if you want to take a shortcut, you include the library, like this ...
using namespace std;
cout<<"hello world"<<endl;
That code would work because you included the library and told the compiler that you would be taking shortcuts.
+ 23
@Himanshu Mishra -- That's correct.
Note: implementing '#include <cstdlib>' instead of 'using namespace std' could also work.
+ 20
It includes the c/c++ standard library.
std::cout << "without library\n";
using namespace std;
cout << "with library" << endl;
It makes programming much more fluent.
+ 16
Agree with Cipher
+ 11
@Cipher Fox Explain your answer. Please
+ 9
Cipher is right. 'using namespace std' means that you are going to access classes, functions or libraries in your code and in order to simplify your code, this statement is used so that you don't have to *explicitly* call the namespace to access them.
*without this statement*
#include<iostream>
std::cout<<"Hello";
*with this statement*
#include<iostream>
using namespace std
cout<<"Hello";
hope this helps
+ 2
But what about the preprocessor directives(iostream)? Aren't they responsible for including the functions and their definitions?
+ 2
preprocesser directive n library



