hi guys can anyone tell me what is the use of namespace with an example and why only namespace std not namespace cout and how I know which type of namespace s are used writing an program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

hi guys can anyone tell me what is the use of namespace with an example and why only namespace std not namespace cout and how I know which type of namespace s are used writing an program?

1st Jan 2016, 1:53 AM
sivasaiprakash
sivasaiprakash - avatar
3 Answers
+ 5
Including "using namespace std" in your code omits the need to write "std::cout" (or anything from the std namespace) every time you wish to use cout/etc. "using std::cout" would work, but only when using cout, you'd need to qualify everything else you wish you use from the std namespace. example of use: using namespace std; cout << "An example\n"; cout << "Another example"; Rather than std::cout << "A third example.\n"; std::cout << "This can become quite tedious"; I hope this may help someone. Good luck programming!
22nd Feb 2016, 8:39 AM
Josh
+ 3
to explain it correctly, let's discuse some basic ideas: first of all, computer is a machine that does not know what to do except for the only lines of codes that you tell. secondly, computer only deals with 1's and 0's. thirdly, compiler transmets your programing language to the language that the computer does understand (1's and 0's ) after that, you shall define the place where the compiler will search for a translation for each word to the computer language ( to 1's and 0's ). so, they pre-defined a way to easly define the space for the compiler which they call standard namespace. hence for easier way of using the programing language, (using namespace std) is being used for the seek of saving time.
26th Jan 2016, 3:28 PM
Ahmed El-Sayed
Ahmed El-Sayed - avatar
+ 2
basically the reason you put using namespace std; is to not type std::cout but instead type just cout
14th Apr 2016, 3:51 PM
Sky