std::string or vector<BYTE>

M

Mosfet

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 ?
 
M

Mosfet

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);
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top