Board index » cppbuilder » Strange behaviour of stringstream in BCB5

Strange behaviour of stringstream in BCB5


2007-02-15 06:41:49 AM
cppbuilder83
My code looks like this:
void func(std::ostream &out, std::istream &in)
{
std::stringstream ss;
ss << in.rdbuf();
char ch;
while ( ss.get(ch) )
out.put(ch);
}
(The code is structured this way because there is some other
processing going on that is not part of the problem so I have
omitted it).
The problem is that about 1 time in 100,000 the output file is
half filled with null characters. The file is about 13K in size;
the first 8192 bytes of output are correct and the rest of it
is null characters.
What might be going on here? Do I need to do any sort of flag
operation on 'ss' after reading into it before I can get
characters out of it? Are there any known bugs with this symptom?
 
 

Re:Strange behaviour of stringstream in BCB5

"Old Wolf" < XXXX@XXXXX.COM >writes:
Quote
My code looks like this:

void func(std::ostream &out, std::istream &in)
{
std::stringstream ss;
ss << in.rdbuf();

char ch;
while ( ss.get(ch) )
out.put(ch);
}

(The code is structured this way because there is some other
processing going on that is not part of the problem so I have
omitted it).

The problem is that about 1 time in 100,000 the output file is
half filled with null characters. The file is about 13K in size;
the first 8192 bytes of output are correct and the rest of it
is null characters.

What might be going on here? Do I need to do any sort of flag
operation on 'ss' after reading into it before I can get
characters out of it? Are there any known bugs with this symptom?
I don't know for sure what would cause that (I don't do many
interesting things with iostreams.) Are you sure that the state of
"in" is valid when you extract its rdbuf?
I'm also having trouble finding documentation on the
std::stringstream::get() function, and wonder what its return value is
when it fails? Are you sure that it's 0?
--
Chris (TeamB);
 

Re:Strange behaviour of stringstream in BCB5

Chris Uzdavinis (TeamB) < XXXX@XXXXX.COM >wrote:
Quote
"Old Wolf" < XXXX@XXXXX.COM >writes:

>void func(std::ostream &out, std::istream &in)
>{
>std::stringstream ss;
>ss << in.rdbuf();
>
>char ch;
>while ( ss.get(ch) )
>out.put(ch);
>}
>
>The problem is that about 1 time in 100,000 the output file
>is half filled with null characters. The file is about 13K in
>size; the first 8192 bytes of output are correct and the rest
>of it is null characters.

Are you sure that the state of
"in" is valid when you extract its rdbuf?
Good thinking. "in" comes from another std::stringstream
that has had lots of stuff <<'d to it by a fairly complicated
function so it's conceivable that something might be happening
there, I'll check it out.
Quote
I'm also having trouble finding documentation on the
std::stringstream::get() function, and wonder what its return
value is when it fails? Are you sure that it's 0?
dinkumware.com/manuals/
 

{smallsort}