473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ostringstream

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
2 5938

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex Vinokur | last post by:
Is it possible to use vector<ostringstream> ? Here is what I have got. =========================================== Windows 2000 CYGWIN_NT-5.0 1.3.22(0.78/3/2) GNU gcc version 3.2 20020927...
6
by: Eric Boutin | last post by:
Hi ! I have a strange problem with a std::ostringstream.. code : #include <sstream> /*...*/ std::ostringstream ss(); ss << "\"\"" << libpath << "\"\" \"\"" << argfilename << "\"\"...
5
by: Als | last post by:
What's the meaning of "freeze" as member of ostringstream class? Is it needed always to call freeze() at the disposal of an ostringstream object? Is it also needed before disposing an istringsteam...
5
by: Simon Pryor | last post by:
I am having some strange problems using std::ostringstream. The simple stuff works okay, but trying to use: std::ostringstream::str(const std::string&) or:...
2
by: Julian | last post by:
I would like to have output from my program to be written to cout as well as a file. (actually, i want several other output options but this should explain my problem in the simplest way). I have...
3
by: Mathieu Malaterre | last post by:
Hello, I am trying to write this simple code: std::ostringstream s; s << 1024; std::cout << s.str() << std::endl; s.str(""); // <- problem s << 512; std::cout << s.str() << std::endl;
3
by: Kyle Kolander | last post by:
I posted this in response to a previous thread but have not gotten any replies back... Hopefully someone has an answer? From looking at sections 27.7.3.2 and 27.7.1.2 of the standard, it appears...
3
by: Bob Altman | last post by:
Hi all, Why doesn't the following unmanaged C++ code work as expected: string s; ostringstream strm(s); // This stream should store results in s strm << 25; cout << s << endl; // s...
3
by: Generic Usenet Account | last post by:
With the deprecated ostrstream class, when the constructor is invoked without arguments, memory is dynamically allocated. In that case the onus on freeing the memory lies with the user. Typically...
11
by: coomberjones | last post by:
I have a few std::strings that I am using to store raw binary data, each of which may very well include null bytes at any point or points. I want to slap them together into a single string, so I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.