std::cout vs cout

Discussion in 'C++' started by Pmb, Jun 2, 2004.

  1. Pmb

    Pmb Guest

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

    thanks

    Pmb
     
    Pmb, Jun 2, 2004
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Jun 2, 2004
    #2
    1. Advertising

  3. Pmb

    Leor Zolman Guest

    On Wed, 02 Jun 2004 10:30:45 -0400, Victor Bazarov
    <> 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
     
    Leor Zolman, Jun 2, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Ram

    Re: cout vs std::cout

    Stefan Ram, Sep 28, 2008, in forum: C++
    Replies:
    7
    Views:
    513
  2. Hendrik Schober

    Re: cout vs std::cout

    Hendrik Schober, Sep 28, 2008, in forum: C++
    Replies:
    7
    Views:
    464
    Jerry Coffin
    Oct 7, 2008
  3. Matthias Buelow

    Re: cout vs std::cout

    Matthias Buelow, Sep 28, 2008, in forum: C++
    Replies:
    10
    Views:
    626
    Hendrik Schober
    Oct 1, 2008
  4. saurabh29789

    Sending std::cout to std::cout !!

    saurabh29789, Jun 11, 2009, in forum: C++
    Replies:
    1
    Views:
    313
    Harald Finster
    Jun 11, 2009
  5. saurabh29789

    Sending std::cout to std::cout

    saurabh29789, Jun 11, 2009, in forum: C++
    Replies:
    2
    Views:
    359
    Rolf Magnus
    Jun 12, 2009
Loading...

Share This Page