#include <iostream>
#include <stdio.h>
using namespace std;
struct Test{
int b;
char a;
};
int main() {
//定义结构
Test test[3]={{100,'a'},{100,'b'},{100,'c'}};
//将结构体数据转万能指针
void *voidBuff=(void *)test;
char *charBuff=(char *)voidBuff;
//打印指针byte内容
for(int i=0;i<sizeof(struct Test)*3;i++)
{
printf("%d\n",*charBuff);
charBuff++;
}
//将万能指针存储文件
FILE * out=fopen("1.bin","wb");
fwrite(voidBuff,sizeof(struct Test),3,out);
fclose(out);
return 0;
}
网友评论