0
我試圖讓我的緩衝區複製到另一個緩衝區,但我無法獲得實際值。問題:獲取緩衝區數據
這裏是我的程序是如何流動的: 1.創建隨機整數 2.將它轉換成char 3.將它們變成STL容器 4.從容器中檢索第一個元素 5.轉換成INT形式
這裏是我的頭文件:
struct BufferData
{
char *m_BufferData;
int m_Size;
};
private:
typedef std::vector<BufferData *>BufferVector;
BufferVector m_RecvBuffer1, m_RecvBuffer2, m_RecvBuffer3;
typedef std::vector<BufferData *>::iterator BufferVectorIterator;
BufferVectorIterator IterBuffer1, IterBuffer2, IterBuffer3;
這裏是我的CPP文件:
只考慮步驟#4 #5。
void CUdpSocket::GetEachBuffer(char *BufferSource1, char *BufferSource2, char *BufferSource3)
{
if(!m_RecvBuffer1.empty())
{
IterBuffer1 = m_RecvBuffer1.begin();
memcpy(BufferSource1, *IterBuffer1, BUFFER_SIZE);
m_RecvBuffer1.erase(IterBuffer1);
}
else
memcpy(BufferSource1, 0, BUFFER_SIZE);
if(!m_RecvBuffer2.empty())
{
IterBuffer2 = m_RecvBuffer2.begin();
memcpy(BufferSource2, *IterBuffer2, BUFFER_SIZE);
m_RecvBuffer2.erase(IterBuffer2);
}
else
memcpy(BufferSource2, 0, BUFFER_SIZE);
if(!m_RecvBuffer3.empty())
{
IterBuffer3 = m_RecvBuffer3.begin();
memcpy(BufferSource3, *IterBuffer3, BUFFER_SIZE);
m_RecvBuffer3.erase(IterBuffer3);
}
else
memcpy(BufferSource3, 0, BUFFER_SIZE);
}
這裏是我的輸出:
m_RecvBuffer1 [1](0x0034feb8 {m_BufferData=0x0034bc28 "45" m_Size=4 })
BufferSource1 0x0034bca8 "(¼4" char *
現在,你可以看到我的BufferSource1成爲(¼4
。它應該在char
表格中顯示45。我該如何解決?請幫忙。
謝謝。