#include "iostream"
#include <string.h>
using namespace std;
struct A
{
unsigned short a;
unsigned short b;
}Test1;
struct B
{
unsigned short c;
unsigned short d;
}Test2;
void main()
{
Test1.a = 12345;
Test1.b = 4321;
B *p;
char buff[1024];
int len;
p = (B*)buff;
len = sizeof(B);
memcpy(buff+len,&Test1,sizeof(Test1));
len += sizeof(Test1);
p->c = 678;
p->d = len;
cout<<buff<<endl;
}
这段代码我想把这些数字封装到buff中,可是打印出来是乱码,不知道问题出在哪了,高手帮忙。