stringstream question

M

Marc Schellens

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
 
G

Grzegorz Sakrejda

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::eek:ut);
 
M

Marc Schellens

Grzegorz said:
ioss.rdbuf()->pubseekpos(0,ios_base::in | ios_base::eek:ut);

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
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top