[英]how to print tchar in c++
I am trying to print UCHAR btMACAddress[INTEL_MAC_ADDR_LENGTH]
in c++. 我正在尝试在c ++中打印
UCHAR btMACAddress[INTEL_MAC_ADDR_LENGTH]
。
cout<<"adapter MAC address="<<padapter->btMACAddress<<endl;
IT SHOWING NULL IS ABOVE 显示以上为空
In ci am able to print. ci能够打印。
printf("adapter macaddress %02x:%02x:%02x:%02x:%02x:%02x \n",
pAdapter->adapter[0].btMACAddress[0],
pAdapter->adapter[0].btMACAddress[1],
pAdapter->adapter[0].btMACAddress[2],
pAdapter->adapter[0].btMACAddress[3],
pAdapter->adapter[0].btMACAddress[4],
pAdapter->adapter[0].btMACAddress[5]);
As Joachim pointed out, you can use stream manipulators to control formatting of printed values. 如Joachim所指出的,您可以使用流操纵器来控制打印值的格式。
Required headers file: 必需的头文件:
#include <ios>
#include <iomanip>
#include <iostream>
using namespace std;
Code to print the MAC address: 打印MAC地址的代码:
cout << "adapter macaddress ";
for (int i=0; i<INTEL_MAC_ADDR_LENGTH; i++)
{
if (i > 0) cout << ':';
cout << hex << setw(2) << setfill('0')
<< (unsigned int) pAdapter->adapter[0].btMACAddress[i];
}
cout << endl;
for (int i = 0; i < 6; ++i)
{
cout << pAdapter->adapter[0].btMACAddress[i];
}
cout << endl;
Also this has nothing to do with printing bytes but with your inability to use cout properly. 同样,这与打印字节无关,但与您无法正确使用cout有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.