今天用MFC做了个简单的程序,具体功能是先输入几个学生的信息,然后可以通过学号来查出这个学生的具体信息,这个程序包括3个对话框,分别是主界面和两个分界面的。我做出来了,编译也通过了,生成了个可执行程序,但是运行时在输入学生的信息时(不是查询),却出现下面的出错提示:
debug assertion failed
program ...(文件路径)
file:afx.inl
ine:122
.......
这是什么意思啊??另外,我输入函数和查询函数的代码如下:
void INPUT::OnDok() /*输入函数的*/
{
// TODO: Add your control notification handler code here
UpdateData();
if(stnumber<10)
{BOOL exist=FALSE;
for(int i=0;i<=9;i++)
{if(ourstudent[i].snumber==number)
{MessageBox("该学号已经存在,请再输入一个");
exist=TRUE;
break;}}
if(!exist)
{ourstudent[i].sname=name;
ourstudent[i].sage=age;
ourstudent[i].ssex=sex;
stnumber++;}
}
else MessageBox("人数已满,无法再添加!");
CDialog::OnOK();
}
void S_SEARCH::OnGo() /*查询函数*/
{
// TODO: Add your control notification handler code here
BOOL succ=FALSE;
UpdateData(FALSE);
for(int i=0;i<=9;i++)
{if(ourstudent[i].snumber==numberout)
{nameout=ourstudent[i].sname;
ageout=ourstudent[i].sage;
sexout=ourstudent[i].ssex;
UpdateData(FALSE);succ=TRUE;
break;}}
if(!succ)
MessageBox("对不起,没有你查找的学号");
}
请各位高手帮帮菜鸟,非常感谢!
debug assertion failed
program ...(文件路径)
file:afx.inl
ine:122
.......
这是什么意思啊??另外,我输入函数和查询函数的代码如下:
void INPUT::OnDok() /*输入函数的*/
{
// TODO: Add your control notification handler code here
UpdateData();
if(stnumber<10)
{BOOL exist=FALSE;
for(int i=0;i<=9;i++)
{if(ourstudent[i].snumber==number)
{MessageBox("该学号已经存在,请再输入一个");
exist=TRUE;
break;}}
if(!exist)
{ourstudent[i].sname=name;
ourstudent[i].sage=age;
ourstudent[i].ssex=sex;
stnumber++;}
}
else MessageBox("人数已满,无法再添加!");
CDialog::OnOK();
}
void S_SEARCH::OnGo() /*查询函数*/
{
// TODO: Add your control notification handler code here
BOOL succ=FALSE;
UpdateData(FALSE);
for(int i=0;i<=9;i++)
{if(ourstudent[i].snumber==numberout)
{nameout=ourstudent[i].sname;
ageout=ourstudent[i].sage;
sexout=ourstudent[i].ssex;
UpdateData(FALSE);succ=TRUE;
break;}}
if(!succ)
MessageBox("对不起,没有你查找的学号");
}
请各位高手帮帮菜鸟,非常感谢!
我估计你的updatedata(true);好像你那里两个全是更新显示
UpdateData(); //updatedata(true);
if(stnumber<10)
{
BOOL exist=FALSE;
for(int i=0;i<=9;i++) //i<=9改成i<stnumber
{
if(ourstudent[i].snumber==number) //snumber从哪里出来的?if(!exist)
{ //中没有ourstudent[i].snumber的赋值语句
MessageBox("该学号已经存在,请再输入一个");
exist=TRUE;
break;
}
}
if(!exist)
{
ourstudent[i].sname=name;
ourstudent[i].sage=age;
ourstudent[i].ssex=sex;
stnumber++;
}
}
else MessageBox("人数已满,无法再添加!");
第三: UpdateData(FALSE); //改成TRUE
for(int i=0;i<=9;i++) //i<=9改成i<stnumber
{
if(ourstudent[i].snumber==numberout)
{
nameout=ourstudent[i].sname;
ageout=ourstudent[i].sage;
sexout=ourstudent[i].ssex;
UpdateData(FALSE);
succ=TRUE;
break;
}
}最后: 你的程序太乱
if(stnumber<10)
{
BOOL exist=FALSE;
for(int i=0;i<=9;i++)
{
if(ourstudent[i].snumber==number)
{
MessageBox("该学号已经存在,请再输入一个");
exist=TRUE;
break;
}
}
if(!exist)
{
ourstudent[i].sname=name;
ourstudent[i].sage=age;
ourstudent[i].ssex=sex;
stnumber++;}
}
else MessageBox("人数已满,无法再添加!");
CDialog::OnOK();
其实你的问题出在结构体数组上,你判断输入的学号是否与下标从0到9的有重复,
请确认以下问题:
1。你的数组长度定义为10吗
2。举个例子:是否有可能你在数组里存了11个数,然而正好第11个学号与输入的学号重复
代码里面的毛病很多啊
3。是否会数组越界,(你程序出错的很多原因都在此)
请问是怎么回事?
1,我数组定义是10个;
2,我在输入时学号和数组下标很不同(你是这个意思吗?)
3,什么叫数组越界?