问题
I understand PBYTE
is unsigned char*
from Windows Data Types.
I want to be able to print all the contents, either using printf()
or cout
:
PBYTE buffer;
ULONG buffersize = NULL;
serializeData(data, buffer, buffersize);
//this function serializes "data" and stores the data in buffer and updates bufferSize)..
Can you help me understand how to print this in C++?
回答1:
If you want to print the memory address that buffer
is pointing at, then you can do it like this:
PBYTE buffer;
ULONG buffersize = 0;
serializeData(data, buffer, buffersize);
//this function serializes "data" and stores the data in buffer and updates bufferSize)...
printf("%p", buffer);
or
std::cout << (void*)buffer;
...
But, if you want to print the contents of the buffer, you need to loop through the buffer and print out each BYTE
individually, eg:
PBYTE buffer;
ULONG buffersize = 0;
serializeData(data, buffer, buffersize);
//this function serializes "data" and stores the data in buffer and updates bufferSize)...
for (DWORD i = 0; i < buffersize; ++i)
{
printf("%02x ", buffer[i]);
or
std::cout << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)buffer[i] << " ";
}
...
来源:https://stackoverflow.com/questions/64378866/how-to-print-out-the-contents-of-a-pbyte