Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

append BYTE[] to CString

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
0
0
US
I'm having a problem appending a BYTE array to a CString.

Code:
BYTE b[17];
    .
    .
    .

CString& string;
    .
    .
    .
string += b;  // Error line


error C2679: binary '+=' : no operator found which takes a right-hand operand of type 'BYTE [17]' (or there is no acceptable conversion)


This is the error I am getting. It's been over 8 years since I last programmed in C++, and I can't seem to find what I need on google.

Also, this is attempting to be compiled with Unicode support.
 
BYTE = unsigned char
What exactly does the BYTE array look like? Is it just ASCII text "abcd" or Unicode text where it would look something like "a\0b\0c\0d\0"?
 
The values in the BYTE array represent hex characters for a file read in binary form.

if pFile is a CFile* and m_pFileData is BYTE[ /*length of document*/] then

pFile->Read (m_pFileData, /*length of document*/);

the BYTE array is filled in such a way that BYTE b[] filled by calling

Code:
UINT nCount = pDoc->GetBytes (nLine * 16, 16, b);


UINT <Class>::GetBytes (UINT nIndex, UINT nCount, PVOID pBuffer)
{
    if (nIndex >= m_nDocLength) // m_nDocLength = DocLength
        return 0;

    UINT nLength = nCount;
    if ((nIndex + nCount) > m_nDocLength)
        nLength = m_nDocLength - nIndex;

    ::CopyMemory (pBuffer, m_pFileData + nIndex, nLength);
    return nLength;
}
 
If the BYTE array contains binary data instead of text, a string container like CString probably isn't the best container to use. I'd use a std::vector<BYTE> (or something like CArray<BYTE> if you really want to use MFC).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top