What is the reason behind using the line using namespace std... And why not <iostream.h> is used why only <iostream> is used?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is the reason behind using the line using namespace std... And why not <iostream.h> is used why only <iostream> is used?!

22nd Jun 2017, 8:38 AM
Simran Jamadar
Simran Jamadar - avatar
3 Answers
+ 18
iostream is a standard header, iostream.h is a non standard header, iostream. h was just common in pre standard c++ and its what iostream evolved from. The built in C++ library routines are kept in the standard namespace. That includes stuff like cout, cin, string, vector, and so many others... Because these tools are used so commonly, it's popular to add "using namespace std" at the top of your source code so that you won't have to type the std:: prefix constantly.😛
22nd Jun 2017, 8:49 AM
Corne
Corne - avatar
22nd Jun 2017, 10:31 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
hey! this is according to latest c++ that we don't have to use ".h" anymore. also namespace is something in easy language that makes easy to connect with classes data members or functions . same in the case with std. we have included iostream header file in which there is class name std which consist of cin and cout members. so to access them you have to use scope resolution operator ' std::cout' but it will make the code lengthy . so to shorten it we use namespace. in that case we dont have to mention scope resolution operator and we can easily specify it as 'cout'. for a reao example chevk out my code it will really help you out. remember to upvote me keep coding. https://code.sololearn.com/cA28OVF96bsy/?ref=app
25th Jun 2017, 8:21 AM
Jaskaran Singh
Jaskaran Singh - avatar