Problem with stringbuf

Discussion in 'C++' started by Andre Paim, Aug 15, 2008.

  1. Andre Paim

    Andre Paim Guest

    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
     
    Andre Paim, Aug 15, 2008
    #1
    1. Advertising

  2. Andre Paim

    Fraser Ross Guest

    "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.
     
    Fraser Ross, Aug 16, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Suurkuusk
    Replies:
    0
    Views:
    4,030
    Andreas Suurkuusk
    Jul 27, 2003
  2. Ted Miller
    Replies:
    0
    Views:
    5,218
    Ted Miller
    Sep 13, 2003
  3. fuenfzig
    Replies:
    1
    Views:
    567
    fuenfzig
    Nov 23, 2006
  4. Replies:
    0
    Views:
    573
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    581
    Bullschmidt
    May 11, 2004
Loading...

Share This Page