By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,413 Members | 999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,413 IT Pros & Developers. It's quick & easy.

ostringstream

P: n/a
bml
For the code below:

ostringstream oss;
oss << "A string using ostreamstring" << endl;
oss.str("");
oss.clear();

"'endl' adds a newline character to and flushes the stream of oss."
What does it mean by "flushes the stream"?

Is there any difference to clear a string content of oss by oss.str("") and
by oss.clear()?

How to remove first 10 bytes from the oss, for the above example, causing
the string content of oss to be "sing ostreamstring"?

How to find the position of "using" inside oss? Say, "using" has a byte
position of 9 for example.

Thanks a lot!

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"bml" <le*****@yahoo.com> wrote in message
news:D0*********************@bgtnsc04-news.ops.worldnet.att.net...
For the code below:

ostringstream oss;
oss << "A string using ostreamstring" << endl;
oss.str("");
oss.clear();

"'endl' adds a newline character to and flushes the stream of oss."
What does it mean by "flushes the stream"?
It means nothing, ostringstream's do not flush.

Is there any difference to clear a string content of oss by oss.str("") and by oss.clear()?
oss.clear() does not clear a string content, so yes there is a difference!

clear(), clears the error state of a stream, it has nothing to do with
content. RTFM I think.

How to remove first 10 bytes from the oss, for the above example, causing
the string content of oss to be "sing ostreamstring"?
That cannot be done, any more than you can remove the first 10 bytes from a
file. If you really need this then

1) get the string from the stringstream
2) remove the first 10 bytes from the string
3) put the string back in the stringstream

How to find the position of "using" inside oss? Say, "using" has a byte
position of 9 for example.
Again this sounds like a string operation. Seems you are using stringstreams
when you should be using strings.

Thanks a lot!


John
Jul 22 '05 #2

P: n/a
bml wrote:
For the code below:

ostringstream oss;
oss << "A string using ostreamstring" << endl;
oss.str("");
oss.clear();

"'endl' adds a newline character to and flushes the stream of oss."
What does it mean by "flushes the stream"?
It moves the data from the buffer to its target. That doesn't really
have a meaning for stringstreams.
Is there any difference to clear a string content of oss by
oss.str("") and by oss.clear()?
Yes. One acutally makes the string empty, the other doesn't. clear()
clears the status bits of the stream.
How to remove first 10 bytes from the oss, for the above example,
causing the string content of oss to be "sing ostreamstring"?
oss.str(oss.str().substr(10));
How to find the position of "using" inside oss? Say, "using" has a
byte position of 9 for example.


string::size_type index = oss.str().find("using");

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.