如何打印PBYTE的内容? [英] How to print out the contents of a PBYTE?
本文介绍了如何打印PBYTE的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我了解 PBYTE
是 Windows数据类型.
我希望能够使用 printf()
或 cout
打印所有内容:
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)..
您能帮助我了解如何在C ++中打印吗?
Can you help me understand how to print this in C++?
推荐答案
如果要打印 buffer
指向的内存地址,则可以执行此操作像这样:
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;
...
但是,如果要打印缓冲区的内容,则需要遍历缓冲区并分别打印出每个 BYTE
,例如:
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] << " ";
}
...
这篇关于如何打印PBYTE的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文