Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problem with stringbuf

Thread Tools

Problem with stringbuf

Andre Paim
Posts: n/a
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::istream_iterator<char>(), std: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?

Reply With Quote
Fraser Ross
Posts: n/a
"Andre Paim"
> #include <iostream>
> #include <iterator>
> #include <istream>
> #include <sstream>

One that you have missed is <algorithm>.

> 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.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove from std::stringbuf C++ 0 04-15-2008 04:49 PM
Stringbuf for concurrent writing And reading fuenfzig C++ 1 11-23-2006 12:38 PM
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM