close
#pragma pack(push,1)
typedef struct _ImageHeader{
short type; /* Magic identifier */
unsigned int size; /* File size in bytes */
unsigned short reserved1;
unsigned short reserved2;
unsigned int offset; /* Offset to image data, bytes */
}ImageHeader;
#pragma pack(pop,1)
//若沒有加#pragma pack(pop,1) 以及 #pragma pack(pop,1)
//fout<<sizeof(ImageHeader)<<endl;//會出現16,實際算才14
CFile f;
f.Open("beagirl.bmp",CFile::modeRead|CFile::typeBinary);
ImageHeader imghder;
f.Read(&imghder,sizeof(imghder));
f.Close();
另一個方法是在VC選項中直接設定
Project=>project setting=>C/C++ Page
在Category選Code Generation在Struct member alignment選擇1Byte
typedef struct _ImageHeader{
short type; /* Magic identifier */
unsigned int size; /* File size in bytes */
unsigned short reserved1;
unsigned short reserved2;
unsigned int offset; /* Offset to image data, bytes */
}ImageHeader;
#pragma pack(pop,1)
//若沒有加#pragma pack(pop,1) 以及 #pragma pack(pop,1)
//fout<<sizeof(ImageHeader)<<endl;//會出現16,實際算才14
CFile f;
f.Open("beagirl.bmp",CFile::modeRead|CFile::typeBinary);
ImageHeader imghder;
f.Read(&imghder,sizeof(imghder));
f.Close();
另一個方法是在VC選項中直接設定
Project=>project setting=>C/C++ Page
在Category選Code Generation在Struct member alignment選擇1Byte
全站熱搜
留言列表