刚写了一段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);
}