C語言中往緩存寫入結構體的方法
typedef struct Cmytype
{
int a;
char b;
};
main()
{
char buffer[100];
Cmytype data1,data2;
data1.a = 100;
data1.b = 'a';
data2.a = 119;
data2.b = 'b';
//寫入緩存
((Cmytype *)buffer)[0] = data1;
((Cmytype *)buffer)[1] = data2;
//檢驗寫入的正確性
Cmytype result1 = ((Cmytype *)buffer)[0];
Cmytype result2 = ((Cmytype *)buffer)[1];
cout<<result1.a<<endl<<result1.b<<endl;
cout<<result2.a<<endl<<result2.b<<endl;
}