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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top