473,396 Members | 2,024 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,396 software developers and data experts.

stringstream question


class myClass
{
stringstream ioss;
istream* is;
void f()
{
....
string initStr("");
ioss.str( initStr);
ioss.seekg( 0);
ioss.clear();
is->get( *ioss.rdbuf());
.....
}

public:
myClass( istream* is_): ioss(), is( is_) {}

....
};

works well, but:

void f()
{
....
// string initStr("");
ioss.str( ""); // HERE
ioss.seekg( 0);
ioss.clear();
is->get( *ioss.rdbuf());
.....
}
causes the program reproducible to fail.
Is there something obvious wrong? (compiles without warning)
Is there a easier/better/clearer way to reset a stringstream?

thanks,
marc

Jul 19 '05 #1
2 3310
On Tue, 04 Nov 2003 12:03:48 +0900, Marc Schellens
<m_*********@hotmail.com> wrote:

class myClass
{
stringstream ioss;
istream* is;
void f()
{
...
string initStr("");
ioss.str( initStr);
ioss.seekg( 0);
ioss.clear();
is->get( *ioss.rdbuf());
....
}

public:
myClass( istream* is_): ioss(), is( is_) {}

...
};

works well, but:

void f()
{
...
// string initStr("");
ioss.str( ""); // HERE
ioss.seekg( 0);
ioss.clear();
is->get( *ioss.rdbuf());
....
}
causes the program reproducible to fail.
Is there something obvious wrong? (compiles without warning)
Is there a easier/better/clearer way to reset a stringstream?

thanks,
marc


ioss.rdbuf()->pubseekpos(0,ios_base::in | ios_base::out);

--
grzegorz
Jul 19 '05 #2
Grzegorz Sakrejda wrote:
On Tue, 04 Nov 2003 12:03:48 +0900, Marc Schellens
<m_*********@hotmail.com> wrote:

class myClass
{
stringstream ioss;
istream* is;
void f()
{
...
string initStr("");
ioss.str( initStr);
ioss.seekg( 0);
ioss.clear();
is->get( *ioss.rdbuf());
....
}

public:
myClass( istream* is_): ioss(), is( is_) {}

...
};

works well, but:

void f()
{
...
// string initStr("");
ioss.str( ""); // HERE
ioss.seekg( 0);
ioss.clear();
is->get( *ioss.rdbuf());
....
}
causes the program reproducible to fail.
Is there something obvious wrong? (compiles without warning)
Is there a easier/better/clearer way to reset a stringstream?

thanks,
marc


ioss.rdbuf()->pubseekpos(0,ios_base::in | ios_base::out);


Thank you, but it does not work.
The buffer is overridden, but the contents is kept:

FMTIn::GetLine: 1.
FMTIn::GetLine: 2.34.
FMTIn::GetLine: 5.34.

The stream (is) was:
1
2.34
5


Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ellarco | last post by:
Im sorry for asking a question that is surely in the archives somewhere, but I have been unable to locate it. Its about string memory management. I need to dynamically construct a C-style string...
3
by: Mike Chirico | last post by:
Sorry about the newbie question. What's the best way to convert numbers to strings in C++. The following works, but is it better than using the sprintf() "old C" way of converting? #include...
6
by: Christopher Benson-Manica | last post by:
This is a subtle variation of a question I posted some time ago. #include <map> #include <iostream> #include <sstream> int main(void) { try { std::stringstream s;
5
by: cherico | last post by:
I'd like to read stings from cin and put them in stringstream. I use a string object as an intermediate "container" to store data from cin and then put them in stringstream. stringstream ss ;...
5
by: William Payne | last post by:
How do you get rid the contents in a std::stringstream? I'm using one in a for loop to format some status messages which I print to the screen. The stringstream member function clear() only clears...
3
by: mlm | last post by:
Hi, I believe that it should not be legal to create a vector (and array) of stringstream since the copy constructor and assignment operators are declared private. However, I don't understand...
9
by: martinezfive | last post by:
Hi, I feel no doubt some documentation contains my answer, so bare with me. Given the following: #inclde <stdio.h> #include <sstream> void f() { std::stringstream a("Hello World!\n");
2
by: DaLoverhino | last post by:
I'm trying to get use to using stringstream and I've run across a case that puzzles me. Perhaps you have some suggestion for the following: Why in the code below for case 2, intVal is always 1?...
0
by: sundman.anders | last post by:
Hi all! I have a question about thread synchronization and c++ streams (iostreams, stringstreams, etc). When optimizing a program for a multicore processor I found that stringstream was causing...
1
by: jjblt206 | last post by:
Hi, I have a simple nit-picky question. It would be nice for a stringstream to have a member function which returns a C style string (just like a string does) so I could do this, stringstream...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.