Re: using namespace std;
On 2006-06-01 11:49, zahy[dot]bnaya[At]gmail[dot]com wrote:
Hi all,
Since I am always confusing this, I want to know once and for all what
is the right way of doing this.
I've noticed that some programs use:
std::cout<< "yadayada"<<endl;
[which I'll call it alternative 1]
Pros: You know what you get.
Cons: A bit more to type.
while some others use:
cout<< "yadayada"<<endl;
usually they have:
using namespace std;
somewhere.
[which I'll call it alternative 2]
Pros: Little less to type.
Cons: Might introduce weird problems. Not recommended.
The problem with "using namespace std;" is that you drag everything from
std into your namespace which might cause problems when there is a
function in std:: that has the same name as one of your functions. I
usually use the third method, "using std::cout;" which lets you use cout
without typing std:: in front of it every time and avoids the problems
with "using namespace std;".
For a more throughout explanation see the faq:
http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
Erik WikstrFm
--
"I have always wished for my computer to be as easy to use as my
telephone; my wish has come true because I can no longer figure
out how to use my telephone" -- Bjarne Stroustrup