What is the nearest equivalent in C++ to the Java ByteArrayOutputStream

Discussion in 'C++' started by Angus, Jan 3, 2007.

  1. Angus

    Angus Guest

    Hello

    I need to port some Java code and am wondering if there is a close
    equivalent to ByteArrayOutputStream.

    I have been looking at the STL iostream library but not quite sure what is
    best to use.

    Any help would be much appreciated.
    Angus, Jan 3, 2007
    #1
    1. Advertising

  2. Angus wrote:
    > I need to port some Java code and am wondering if there is a close
    > equivalent to ByteArrayOutputStream.
    >
    > I have been looking at the STL iostream library but not quite sure
    > what is best to use.
    >
    > Any help would be much appreciated.


    Any standard stream has 'write' member that takes a pointer to char,
    which is probably what you want... What problem are you solving?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jan 3, 2007
    #2
    1. Advertising

  3. Angus

    Angus Guest

    "Victor Bazarov" <> wrote in message
    news:enh3gj$65l$...
    > Angus wrote:
    > > I need to port some Java code and am wondering if there is a close
    > > equivalent to ByteArrayOutputStream.
    > >
    > > I have been looking at the STL iostream library but not quite sure
    > > what is best to use.
    > >
    > > Any help would be much appreciated.

    >
    > Any standard stream has 'write' member that takes a pointer to char,
    > which is probably what you want... What problem are you solving?
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask
    >
    >


    I am working with binary data - so bytes of anything. I am looking at
    stringstream but maybe it won't like embedded control characters etc. Do
    you know if that is the case? If not what to use?
    Angus, Jan 3, 2007
    #3
  4. Angus wrote:
    > "Victor Bazarov" <> wrote in message
    > news:enh3gj$65l$...
    >> Angus wrote:
    >>> I need to port some Java code and am wondering if there is a close
    >>> equivalent to ByteArrayOutputStream.
    >>>
    >>> I have been looking at the STL iostream library but not quite sure
    >>> what is best to use.
    >>>
    >>> Any help would be much appreciated.

    >>
    >> Any standard stream has 'write' member that takes a pointer to char,
    >> which is probably what you want... What problem are you solving?
    >>
    >> V
    >> --
    >> Please remove capital 'A's when replying by e-mail
    >> I do not respond to top-posted replies, please don't ask
    >>
    >>

    >
    > I am working with binary data - so bytes of anything. I am looking at
    > stringstream but maybe it won't like embedded control characters etc.


    Ah... No such thing as "embedded control characters" in C++, AFAIK.
    'char' and 'unsigned char' are just integral types with value ranges.

    > Do you know if that is the case? If not what to use?


    No, it's not the case. It seems you just need 'basic_stringstream' with
    'unsigned char' as its first argument:

    std::basic_stringstream<unsigned char> mystream;

    (if unsigned char [0..255] is the requirement, Java's 'byte' is actually
    unsigned) or use std::stringstream if 'char' is fine; you may need to
    cast to unsigned char later.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jan 3, 2007
    #4
    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. Steve
    Replies:
    5
    Views:
    42,651
    Steve
    May 17, 2004
  2. Fred
    Replies:
    3
    Views:
    63,475
  3. Ido M. Tamir
    Replies:
    1
    Views:
    2,771
    John C. Bollinger
    Jun 24, 2004
  4. Googy
    Replies:
    3
    Views:
    225
    James Edward Gray II
    Jun 29, 2007
  5. Martin DeMello
    Replies:
    1
    Views:
    95
    Martin DeMello
    Feb 14, 2010
Loading...

Share This Page