By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

std::cout vs cout

P: n/a
Pmb
I've noticed a lot of people preferring std::cout over cout. May I ask why
you prefer one over the other?

thanks

Pmb
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Pmb wrote:
I've noticed a lot of people preferring std::cout over cout. May I ask why
you prefer one over the other?


'cout' is half as short to type. OTOH, to use it you need to declare
the name 'std::cout' as _used_ in the current scope, which is commonly
done by means of 'using' declaration, which in itself a kind of blanket
statement. Often, you might not want to bring the name into the scope
and instead use the "full" form. You know, like calling somebody "Mr.
Firstname Lastname" instead of "sir".

I prefer using most of standard types and objects with the namespace
prefix, unless I am being lazy, in which case I usually just say 'using
namespace std;'.

Victor
Jul 22 '05 #2

P: n/a
On Wed, 02 Jun 2004 10:30:45 -0400, Victor Bazarov
<v.********@comAcast.net> wrote:
Pmb wrote:
I've noticed a lot of people preferring std::cout over cout. May I ask why
you prefer one over the other?
'cout' is half as short to type. OTOH, to use it you need to declare
the name 'std::cout' as _used_ in the current scope, which is commonly
done by means of 'using' declaration, which in itself a kind of blanket
statement. Often, you might not want to bring the name into the scope
and instead use the "full" form. You know, like calling somebody "Mr.
Firstname Lastname" instead of "sir".

I prefer using most of standard types and objects with the namespace
prefix, unless I am being lazy, in which case I usually just say 'using
namespace std;'.


The "middle ground" is to bring the names you want into scope via using
/declarations/ rather than the directive:

using std::cout;
using std::endl;

Following the most recent discussion of the perils of the using directive,
I've edited my default testing template so that it contains the two
declarations above (bringing in the identifiers I most commonly use in my
little hack test programs), in place of my original
using namespace std;
directive at namespace scope (which, as it continuously gets pointed out,
is evil).
-leor

Victor


--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.