#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
struct test1
{
QString str1;
};
struct test2{
int i;
int j;
test1 A;
};
test2 arr;
int main(int argc, char *argv[])
{
arr.i =1;
arr.j =2;
arr.A.str1 = "HELLO";
int size = sizeof(arr);
char* filename = QString("D://a.txt").toUtf8().data();
//写入文件
FILE* file = fopen(filename, "wb");
fwrite(&arr, size, 1, file);
fclose(file);
int fsize;
file = fopen(filename, "rb");
//反转
fseek(file, 0, SEEK_END);
fsize = ftell(file);
rewind(file);
//读出文件
unsigned char *data = (unsigned char*)malloc(fsize);
fread(data, fsize, 1, file);
fclose(file);
test2* aim = (test2*)data;
qDebug()<<aim->i<<aim->j<<aim->A.str1;
free(data);
return 0;
}
07-28
07-28
07-28
07-28