Sending std::cout to std::cout

Discussion in 'C++' started by saurabh29789, Jun 11, 2009.

  1. saurabh29789

    saurabh29789 Guest

    I have a statement I'd like you to consider :

    std::cout<<(std::cout<<"Hi");

    that prints a Hii followed by some address.

    The (std::cout<<"Hi") would be returning an object of type ostream,
    but what is this address that is printed ?? How??
     
    saurabh29789, Jun 11, 2009
    #1
    1. Advertising

  2. saurabh29789

    Tim Slattery Guest

    saurabh29789 <> wrote:

    >I have a statement I'd like you to consider :
    >
    >std::cout<<(std::cout<<"Hi");
    >
    >that prints a Hii followed by some address.
    >
    >The (std::cout<<"Hi") would be returning an object of type ostream,
    >but what is this address that is printed ?? How??


    It's printing the address of the std::cout object.

    --
    Tim Slattery

    http://members.cox.net/slatteryt
     
    Tim Slattery, Jun 11, 2009
    #2
    1. Advertising

  3. saurabh29789

    Rolf Magnus Guest

    Tim Slattery wrote:

    > saurabh29789 <> wrote:
    >
    >>I have a statement I'd like you to consider :
    >>
    >>std::cout<<(std::cout<<"Hi");
    >>
    >>that prints a Hii followed by some address.
    >>
    >>The (std::cout<<"Hi") would be returning an object of type ostream,
    >>but what is this address that is printed ?? How??

    >
    > It's printing the address of the std::cout object.


    No. Well, maybe or maybe not. It's printing some address that is not NULL,
    because std::eek:stream has a conversion operator to void* that returns a null
    pointer if the stream encountered an error or some non-null poiner if it
    didn't.
     
    Rolf Magnus, Jun 12, 2009
    #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. Pmb

    std::cout vs cout

    Pmb, Jun 2, 2004, in forum: C++
    Replies:
    2
    Views:
    4,411
    Leor Zolman
    Jun 2, 2004
  2. Stefan Ram

    Re: cout vs std::cout

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

    Re: cout vs std::cout

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

    Re: cout vs std::cout

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

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

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

Share This Page