Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Problem with stringbuf

 
 
Andre Paim
Guest
Posts: n/a
 
      08-15-2008
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: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
 
Reply With Quote
 
 
 
 
Fraser Ross
Guest
Posts: n/a
 
      08-16-2008
"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.

Fraser.


 
Reply With Quote
 
 
 
Reply

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 marco.minerva@gmail.com 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



Advertisments