difference between std::ostringstream and std::ostream

Discussion in 'C++' started by Pallav singh, Oct 21, 2009.

  1. Pallav singh

    Pallav singh Guest

    Hi All

    what is the difference between std::eek:stringstream and ostream ?

    example :
    int reel = 10 ;
    std::eek:stringstream output;
    std::eek:stream out;
    output << "ReelStripBG" << reel;
    out<<reel;

    Thanks
    Pallav Singh
    Pallav singh, Oct 21, 2009
    #1
    1. Advertising

  2. Pallav singh

    Ian Collins Guest

    Pallav singh wrote:
    > Hi All
    >
    > what is the difference between std::eek:stringstream and ostream ?


    What does your text book tell you? Ah, I forgot, you never reply.

    The noun in the middle of ostringstream gives the game away.

    --
    Ian Collins
    Ian Collins, Oct 21, 2009
    #2
    1. Advertising

  3. Pallav singh

    siddhant3s Guest

    Re: difference between std::eek:stringstream and std::eek:stream

    On Oct 21, 11:09 am, Pallav singh <> wrote:
    > Hi All
    >
    > what is the difference between std::eek:stringstream  and ostream ?


    Well, ostringstream is a derived class from ostream.
    Take a look at the hierarchy of C++ streams : http://www.cplusplus.com/reference/iostream/
    siddhant3s, Oct 21, 2009
    #3
  4. Re: difference between std::eek:stringstream and std::eek:stream

    On Oct 21, 9:09 am, Pallav singh <> wrote:
    > Hi All
    >
    > what is the difference between std::eek:stringstream  and ostream ?
    >
    > example :
    >     int reel = 10 ;
    >     std::eek:stringstream output;
    >     std::eek:stream         out;
    >     output << "ReelStripBG" << reel;
    >     out<<reel;
    >
    > Thanks
    > Pallav Singh


    Hi Pallav
    The difference is almost obvious. The ostream is the standard library
    class
    for (Standard) output device stream. An ostream object like cout is
    connected
    to output device. On the other hand, Using ostrstream class, we can
    connect
    the output stream to string object rather than standard output. The
    ostringstream
    object connects output stream to a string.
    int reel = 10 ;
    std::eek:stringstream output;
    std::eek:stream out; // error: no default ctor
    output << "ReelStripBG"; // put to "ReelStripBG" to a string
    cout << reel; // put to "10" to output stream
    out<<reel; // error
    cout << '\n' << putput.str() << '\n'; // put to "ReelStripBG" to
    a output

    Regards,
    -- Saeed Amrollahi
    Saeed Amrollahi, Oct 21, 2009
    #4
    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. jakk
    Replies:
    4
    Views:
    12,039
  2. Chris
    Replies:
    3
    Views:
    2,007
    Chris
    Feb 17, 2004
  3. Bala2508
    Replies:
    28
    Views:
    1,149
    Jim Langston
    Nov 3, 2007
  4. Replies:
    2
    Views:
    1,882
  5. , India
    Replies:
    3
    Views:
    2,825
    James Kanze
    Nov 13, 2010
Loading...

Share This Page