Solved

ostringstream

Posted on 2003-12-07
2
197 Views
Last Modified: 2010-04-01
Hello, could somebody demostrate me how function ostringstream (ang generally memory streams?

thank you
0
Comment
Question by:xLeon
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
monkesdb earned 50 total points
ID: 9891827
well an outputstream has the  << operator overloaded an inputstream has the >> operator overloaded.

with file streams you are reading and writing to/from a file. but with string streams you are reading or writing strings


-------------------------
ostringstream oss();

oss << "hello";
oss << " ";
oss << "world";

string s = oss.str();

assert(s == "hello world");

--------------------------

string s;
ostringstream oss(s);

oss << "hello";
oss << " ";
oss << "world";

assert(s == "hello world");
0
 
LVL 3

Expert Comment

by:monkesdb
ID: 9891831
the first example shows you how to get the stored string, the second shows you how to associate the stream with a string.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lambda for random numbers problem 7 120
FMX enumerated colours 2 133
Outlook 13 84
How to intercept WM_INITDIALOG, WM_CREATE, WM_COMMAND message for Office apps or Notepad? 5 69
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question