|
#include<iostream>
using namespace std;
#include<stdio.h>
#include<stdlib.h>
class group_1
{
public:
void find(void);
};
group_1 everyone;
class group_2
{
public:
void add(void);
void modify(void);
};
group_2 select_few;
class group_3
{
public:
void add(void);
void modify(void);
void remove(void);
};
group_3 heath;
int main()
{
char string[2],option='\0';
int i,*intptr;
char *password,*charptr;
cout<<"please enter password: ";
charptr=gets(password);
i=atoi(charptr);
while(option!='q')
{
cout<<"please enter option: \n";
cout<<"<a>dd,<f>ind,<m>odify,<d>elete or <q>uit : ";
cin>>option;
switch(option)
{
case 'a':
if(i==10||i==20)
{
select_few.add();
}
else if(i==99)
{
heath.add();
}
else
cout<<"permission denied!\n";
break;
case 'f':
everyone.find();
break;
case 'm':
if(i==10||i==20)
{
select_few.modify();
}
else if(i==99)
{
heath.modify();
}
else
cout<<"permission denied!\n";
break;
case 'd':
if(i==99)
heath.remove();
else
cout<<"permission denied!\n";
break;
case 'q':
break;
default:
cout<<"invalid input!please re_enter!\n";
}
}
}
void group_1::find(void)
{
cout<<"inside group_1 find()\n";
}
void group_2::add(void)
{
cout<<"inside group2 add()\n";
}
void group_2::modify()
{
cout<<"inside group2 modify()\n";
}
void group_3::add(void)
{
cout<<"inside group3 add()\n";
}
void group_3::modify()
{
cout<<"inside group3 modify()\n";
}
void group_3::remove()
{
cout<<"inside group_3 remove()\n";
}
在上面的一段程序中有这么一段:
char string[2],option='\0';
int i,*intptr;
char *password,*charptr;
cout<<"please enter password: ";
charptr=gets(password);
i=atoi(charptr);
运行后,先输入password,但是输入后一按回车就出现内存不能读的错误,
但是我稍微改一下把charptr=gets(password);i=atoi(charptr)改为cin>>i后就没事了,是怎么回事啊,
请大家帮我解释一下 |
|