std::string or vector<BYTE>

Discussion in 'C++' started by Mosfet, Mar 2, 2009.

  1. Mosfet

    Mosfet Guest

    Hi,

    I would like to retrieve a stream containing a unicode string, so I
    would like to know what is the best methode to retrieve this stream.
    Here is what is currently done :

    do
    {
    pStream->Read(szBuf, 255, &ulNumChars);
    if (ulNumChars >0)
    {
    static CString strBodyPart;

    memmove(strBodyPart.GetBuffer(ulNumChars), szBuf, ulNumChars);
    strBody += strBodyPart;
    strBodyPart.ReleaseBuffer(ulNumChars);
    }
    } while (ulNumChars >= 255);




    I would like to replace this code by something portable and I don't know
    if I should use a vector<BYTE> or a std::string.
    How would you do it in a efficient maner ?
    Mosfet, Mar 2, 2009
    #1
    1. Advertising

  2. Mosfet

    Mosfet Guest

    Mosfet a écrit :
    > Hi,
    >
    > I would like to retrieve a stream containing a unicode string, so I
    > would like to know what is the best methode to retrieve this stream.
    > Here is what is currently done :
    >
    > do
    > {
    > pStream->Read(szBuf, 255, &ulNumChars);
    > if (ulNumChars >0)
    > {
    > static CString strBodyPart;
    >
    > memmove(strBodyPart.GetBuffer(ulNumChars), szBuf, ulNumChars);
    > strBody += strBodyPart;
    > strBodyPart.ReleaseBuffer(ulNumChars);
    > }
    > } while (ulNumChars >= 255);
    >
    >
    >
    >
    > I would like to replace this code by something portable and I don't know
    > if I should use a vector<BYTE> or a std::string.
    > How would you do it in a efficient maner ?

    Finally I did this :


    std::vector<BYTE> arrByte;
    arrByte.reserve(255);

    do
    {
    hr = pStream->Read(szBuf, 255, &ulNumChars);
    if (ulNumChars >0)
    {
    arrByte.insert(arrByte.end(), szBuf, szBuf+ulNumChars);
    }
    } while (ulNumChars >= 255);
    Mosfet, Mar 2, 2009
    #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. Vince
    Replies:
    16
    Views:
    5,574
    White Wolf
    Jan 20, 2005
  2. Anonymous
    Replies:
    20
    Views:
    4,254
    Pete Becker
    Mar 30, 2005
  3. Jason Heyes
    Replies:
    8
    Views:
    703
    Andrew Koenig
    Jan 15, 2006
  4. Replies:
    8
    Views:
    1,877
    Csaba
    Feb 18, 2006
  5. Rune Allnor
    Replies:
    4
    Views:
    917
    Rune Allnor
    Dec 11, 2008
Loading...

Share This Page