+ 16

[DUPLICATE] Using Namespace Std

What is the use of the code "using Namespace Std"??

24th Apr 2017, 2:36 AM
Dipan Nanda
Dipan Nanda - avatar
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.
24th Apr 2017, 3:01 AM
Fox
Fox - avatar
+ 23
@Himanshu Mishra -- That's correct. Note: implementing '#include <cstdlib>' instead of 'using namespace std' could also work.
25th Apr 2017, 11:15 AM
Fox
Fox - avatar
+ 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.
24th Apr 2017, 2:44 AM
Fox
Fox - avatar
+ 16
Agree with Cipher
24th Apr 2017, 3:21 AM
Sachin Artani
Sachin Artani - avatar
+ 11
@Cipher Fox Explain your answer. Please
24th Apr 2017, 2:54 AM
Dipan Nanda
Dipan Nanda - avatar
+ 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
24th Apr 2017, 3:13 AM
Tamoghna Saha
+ 2
But what about the preprocessor directives(iostream)? Aren't they responsible for including the functions and their definitions?
24th Apr 2017, 3:05 PM
Himanshu Mishra
Himanshu Mishra - avatar
+ 2
preprocesser directive n library
25th Apr 2017, 7:11 PM
imtiaz Ahmad
imtiaz Ahmad - avatar