Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

不能输入数据 #4372

Closed
SYQ0312 opened this issue Aug 2, 2020 · 1 comment
Closed

不能输入数据 #4372

SYQ0312 opened this issue Aug 2, 2020 · 1 comment

Comments

@SYQ0312
Copy link

SYQ0312 commented Aug 2, 2020

#include
#include
#include<malloc.h>
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
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants