结构体中的指针
结构体
struct meta_zjzh
{
int points;
short level;
char brokertel[16];
char brokeremail[32];
char brokername[16];
short buf[1];
};
写文件
void WriteZJZH()
{
CFile file;
CString strZJZHPath;
strZJZHPath="zjzh.dat";
if (file.Open(strZJZHPath,CFile::modeWrite|CFile::modeCreate|CFile::shareDenyNone))
{
struct meta_zjzh Kehuinfo;
memset(&Kehuinfo,0,sizeof(meta_zjzh));
Kehuinfo.level = 1;
Kehuinfo.points = 1008;
strcpy(Kehuinfo.brokername , "黄颜");
strcpy(Kehuinfo.brokeremail , "beautifulgirl@163.com");
strcpy(Kehuinfo.brokertel , "0755-88888888");
file.Write(&Kehuinfo,sizeof(struct meta_zjzh));
file.Close();
}
}
请问怎么写入3个short进去:1001,1002,1003
然后将其读出来
读文件
void UpdateZJZH()
{
CFile file;
CString strZJZHPath;
strZJZHPath="zjzh.dat";
if (file.Open(strZJZHPath,CFile::modeRead|CFile::shareDenyNone))
{
struct meta_zjzh Kehuinfo;
file.Read(&Kehuinfo,sizeof(struct meta_zjzh));
level = Kehuinfo.level;
point = Kehuinfo.points;
MgrName = Kehuinfo.brokername;
MgrEmail = Kehuinfo.brokeremail;
MgrTel = Kehuinfo.brokertel;
int a = file.GetLength();
int b = sizeof(Kehuinfo);
int n = (file.GetLength()-sizeof(meta_zjzh)+2)/2;
short* buff = new short[n];
file.Read(&buff,n);
file.Close();
}
}