+ 1

What is the main purpose of using "using namespace std" in c++ coding? Is it possible to skip this step or any alternative?

27th Jul 2017, 10:55 PM
Vinamra Kishore
Vinamra Kishore - avatar
11 Antworten
+ 7
ok. sure. the namespace std includes many many functions not just cin cout. there are things with common type names also, take min or max as an example. say we want to create our own max function, if we were exposing the entire namespace with 'using namespace std' our max function would cause an error. as the compiler would not know which max we mean. our own or the built in one.
27th Jul 2017, 11:12 PM
jay
jay - avatar
+ 10
We have a nice local thread on namespaces too. :> https://www.sololearn.com/Discuss/294730/?ref=app
28th Jul 2017, 2:22 AM
Hatsy Rei
Hatsy Rei - avatar
+ 9
or list each function you will be using. like using std::cout; using std::endl;
27th Jul 2017, 11:01 PM
jay
jay - avatar
+ 7
you can always use std:: for example: std::cout << "hay" << std::endl;
27th Jul 2017, 10:58 PM
Jordan Chapman
Jordan Chapman - avatar
+ 7
@Vinamra: yes. but this is not so bad, it is very explicit and will avoid any naming conflicts that may arise in larger code bases
27th Jul 2017, 11:03 PM
jay
jay - avatar
+ 7
just a note. Using namespace std isnt bad while learning or really small codes
27th Jul 2017, 11:28 PM
jay
jay - avatar
27th Jul 2017, 11:15 PM
jay
jay - avatar
+ 2
thanks Jordan,but if I escape "using namespace std" step then will I have to use "std" before every "cout" or "cin" or any other functions?
27th Jul 2017, 11:01 PM
Vinamra Kishore
Vinamra Kishore - avatar
+ 1
@jay: I didn't understand what naming conflicts here mean,do clear this doubt.!!
27th Jul 2017, 11:07 PM
Vinamra Kishore
Vinamra Kishore - avatar
+ 1
thanks@ Jay
27th Jul 2017, 11:20 PM
Vinamra Kishore
Vinamra Kishore - avatar
+ 1
I have gone through some big codes of yours and others. found out why we should escape this function. :)
27th Jul 2017, 11:49 PM
Vinamra Kishore
Vinamra Kishore - avatar