typedef struct Info
{
char name[5];
char addr[10];
int age;
double salary;
}tInfo, *pInfo;
//tInfo为结构体Info的别名
struct stTest
{
char name[5];
char addr[10];
int age;
double salary;
};
int _tmain(int argc, _TCHAR* argv[])
{
//结构体指针的创建、置空、赋值
pInfo info = new tInfo();
memset(info, 0 ,sizeof(tInfo));
info->age = 10;
strcpy(info->name, "zhou");
strcpy(info->addr,"shandong");
info->salary = 123.123;
//指针的大小为4,结构体的大小采用对齐模式,32位下是4字节对齐
//下面的计算为:32 = 8+12+4+8
int a = sizeof(tInfo);//32
int b = sizeof(Info);//32
int c = sizeof(pInfo);//4
int d = sizeof(info);//4
//结构体转为string
string str;
str.assign((const char*)info, sizeof(tInfo));
//把string转为结构体
pInfo get = new tInfo();
memcpy(get, str.c_str(), str.size());
//结构体对象创建、置空、赋值
stTest st;
memset(&st, 0, sizeof(stTest));
strcpy(st.addr, "shandong");
st