difference between std::ostringstream and std::ostream

P

Pallav singh

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
 
I

Ian Collins

Pallav said:
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.
 
S

Saeed Amrollahi

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top