注册 登录
编程论坛 C++教室

est4.exe 中的 0x00e11a48 处有未经处理的异常: 0xC0000005: 读取位置 0xcde1c6f0 时发生访问冲突

a874695162 发布于 2014-08-23 15:23, 3462 次点击
程序代码:
// test4.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;
struct student
{
    int num;
    int score[3];
    char name[20];
};
void input(student &);
void print(student &);
int main()
{
    student stu[5];
    for(int i=0;i<5;i++)
    {
        cout<<"请输入学生"<<i+1<<"的数据"<<endl;
            input(stu[i]);
    }
    cout<<"您想查询哪个学生的数据?(请输入序号)"<<endl;
        int i;
    cin>>i;
    print(stu[i-1]);
    return 0;
}
void input(student &a)
{
    cout<<"学号:"<<endl;
    cin>>a.num;
    cout<<"姓名:"<<endl;
    cin>>a.name;
    for(int i=0;i<3;i++)
    {
        cout<<""<<i+1<<"科成绩"<<endl;
        cin>>a.score[i];
    }
}
void print(student &b)
{
    cout<<b.num<<"    ";
    cout<<b.name<<"    ";
    for(int i=0;i<3;i++)
        cout<<b.score[i]<<"    ";
}
5 回复
#2
zklhp2014-08-23 16:10
我编译运行了一下没有问题 不知道你怎么操作的
#3
a8746951622014-08-23 16:17
回复 2 楼 zklhp
可能是输入时的问题吧,数据是我随便打的,可能是没注意name的长度(请问,有这个可能吗?)
#4
zklhp2014-08-23 16:28
以下是引用a874695162在2014-8-23 16:17:15的发言:

可能是输入时的问题吧,数据是我随便打的,可能是没注意name的长度(请问,有这个可能吗?)



C++代码不推荐使用数组 应该用容器和string类来代替
#5
stop12042014-08-24 07:54
回复 2 楼 zklhp
我运行就崩溃
#6
stop12042014-08-24 08:15
运行你代码 exit code 3221225477
访问错误  : 如果  i 接受到的数字是 <= 0 的话 那就会出错

然后 输入错误的类型,直接结束程序.  
你加个判断数据类型与接收的变量类型不同就重新输入即可.
1