Problem with stringbuf

A

Andre Paim

The following program:

#include <iostream>
#include <iterator>
#include <istream>
#include <sstream>

int main()
{
char buffer[] = {0x01, 0x0C, 0x1B};
std::stringbuf str_buf;
str_buf.pubsetbuf(buffer, sizeof (buffer));
std::istream iss(&str_buf);
std::cout.setf( std::ios::hex, std::ios::basefield );
std::copy(std::istream_iterator<char>(iss),
std::istream_iterator<char>(), std::eek:stream_iterator<unsigned
short>(std::cout, " "));
return (0);

Generates the output (gcc 4.2 on Linux):

1 1b

Why it does not print the 0x0C value?

Is there any way to modify this program in order to print the 3 bytes?

Regards,
Andre
 
F

Fraser Ross

"Andre Paim"
#include <iostream>
#include <iterator>
#include <istream>
#include <sstream>

str_buf.pubsetbuf(buffer, sizeof (buffer));

setbuf in basic_streambuf only returns the this pointer. I don't think
it is overridden in basic_stringbuf. You are expecting it to call setg
to set up the get area. The Dinkumware library does not override it and
the get area isn't set up.

std::cout.setf( std::ios::hex, std::ios::basefield );

The format flags are in ios_base.

Fraser.
 

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,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top