C++写文件问题

 刚写了一段MFC版的学生管理系统,当写入学生信息的时候,总是出现乱码,这是为什么???

struct student
{
 CString stuId;
 CString stuName;
 int m_cScore;
 int m_mfcScore;
 int m_jspScore;
}m_student;//结构体

 

 

void CStudentDlg::OnButton1()
{
 // TODO: Add your control notification handler code here
 UpdateData();
 m_aveScore = (m_cScore + m_jspScore + m_mfcScore) / 3;

 fstream file;
 file.open("stuInfo.dat",ios::binary | ios::out | ios::trunc/*如果存在则删除原有内容*/);
 if(!file)
 {
  MessageBox("打开失败",NULL,MB_OK);
  return;
 }
 m_student.stuId = m_stuId;
 m_student.stuName = m_stuName;
 m_student.m_cScore = m_cScore;
 m_student.m_jspScore = m_jspScore;
 m_student.m_mfcScore = m_mfcScore;

 

 

 file.write((char *)&m_student,sizeof(m_student));
 
 file.close();
 UpdateData(FALSE);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值