+ 1
What is the main purpose of using "using namespace std" in c++ coding? Is it possible to skip this step or any alternative?
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.
+ 10
We have a nice local thread on namespaces too. :>
https://www.sololearn.com/Discuss/294730/?ref=app
+ 9
or list each function you will be using. like
using std::cout;
using std::endl;
+ 7
you can always use std::
for example:
std::cout << "hay" << std::endl;
+ 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
+ 7
just a note. Using namespace std isnt bad while learning or really small codes
+ 6
try this article. it explains it better 😊
https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
+ 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?
+ 1
@jay: I didn't understand what naming conflicts here mean,do clear this doubt.!!
+ 1
thanks@ Jay
+ 1
I have gone through some big codes of yours and others. found out why we should escape this function. :)