microsoft / RTVS

R Tools for Visual Studio.
MIT License
388 stars 118 forks source link

不能输入数据 #4372

Closed SYQ0312 closed 3 years ago

SYQ0312 commented 3 years ago

include

include

include

using namespace std;

define MAX 1000

void showMenu() { cout << "1.添加联系人" << endl; cout << "2.显示联系人" << endl; cout << "3.删除联系人" << endl; cout << "4.查找联系人" << endl; cout << "5.修改联系人" << endl; cout << "6.清空联系人" << endl; cout << "0. 退出系统 " << endl; } //设计联系人结构体 struct Person { string m_Name; int m_Sex;//性别:1男 2女 int m_Age; string m_Phone; string m_Addr; }; //设计通讯录结构体 struct Addressbooks { struct Person personArray[MAX]; //通讯录中联系人的数组 int m_size; //通讯录中联系人个数 }; //添加联系人 void addPerson(Addressbooks *abs) { //判断通讯录是否已经满了 if (abs->m_size == MAX) { cout << "通讯录已经满了" << endl; return; } else { //添加联系人 string name; cout << "输入需要添加的联系人的姓名:" << endl; cin >> name; abs->personArray[abs->m_size].m_Name = name;

    cout << "输入需要添加的联系人的性别:" << endl;
    cout << "1-----男;2--------女" << endl;

    int sex = 0;
    while (true) {
        cin >> sex;
        if (sex == 1 || sex == 2) {
            abs->personArray[abs->m_size].m_Sex = sex;
            break;
        }
        cout << "输入值应该是1或者2." << endl;
    }
    int age = 0;
    cout << "请输入年龄:" << endl;
    cin >> age;

// cin >> name; // abs->personArray[abs->m_size].m_Name = name; } } //封装添加联系人函数 //测试添加联系人功能 int main() { int select; //main函数中创建通讯录 Addressbooks abs; //struct Addressbooks *abs; while (true) { //菜单调用 showMenu(); //创建一个用户选择变量 cin >> select; switch (select) { case 1: addPerson(&abs); break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 0: cout << "欢迎下次使用" << endl; system("pause"); return 0; break; default: break; } } system("pause"); return 0; } 图片 按1添加联系人时候就会出现异常:读取访问权限冲突

MikhailArkhipov commented 3 years ago

Please stop opening issues on your own code. Try stackoverflow.com if you have programming questions.