关于指针的问题,调试后提示char不能转换为char*
这是代码,希望能求得帮助。#include<iostream>
#include<cstring>
using namespace std;
void namecheck( );
void numcheck( );
class student
{public:
char name[20];
int num;
char sex[5];
double physics;
double English;
double math;
double computer;
double c;
int s;
double total;int ave;
int na[100];
int p[100];
char* getname(){return name;};
int getnum(){return num;};
};
int s;
student na[100];
void main()
{ int q;
int i;
cout<<"学生的总数"<<endl;
cin>>s;
for(i=0;i<s;i++)
{
cout<<"请输入学生姓名"; cin>>na[i].name;
cout<<"请输入学号";cin>>na[i].num;
cout<<"请输入性别";cin>>na[i].sex;
cout<<"请输入物理成绩";cin>>na[i].physics;
cout<<"请输入英语成绩";cin>>na[i].English;
cout<<"请输入数学成绩";cin>>na[i].math;
cout<<"请输入计算机导论成绩";cin>>na[i].computer;
cout<<"请输入C成绩";cin>>na[i].c;
na[i].total=na[i].c+na[i].computer+na[i].English+na[i].math+na[i].physics;
cout<<"总分"<<na[i].total<<endl;
na[i].ave=na[i].total/5;
}
cout<<"请选择查询方式\n按姓名查询请输入1\n按编号查询请输入2\n" ;
cin>>q;
switch(q)
{case 1: namecheck();break;
case 2: numcheck();break;
}
}
void namecheck()
{int j;char* n;
cout<<"请输入姓名"<<endl;
cin>>n;
for(j=0;j<s;j++)
{if(strcmp(na[j].getname(),n)==0)
{ cout<<"查询的人信息如下:"<<endl;
cout<<"姓名\t"<<"学号\t"<<"性别\t"<<"物理\t";
cout<<"英语\t"<<"数学\t"<<"导论\t"<<"C成绩\t"<<"总分\t"<<endl;
cout<<na[j].name<<"\t"<<na[j].num<<"\t"<<na[j].sex<<"\t"<<na[j].physics<<"\t"<<na[j].English<<"\t"<<na[j].math;
cout<<"\t"<<na[j].computer<<"\t"<<na[j].c<<"\t"<<na[j].total<<endl;break;}
}
}
void numcheck()
{int b;int j;
cout<<"请输入学号\n";cin>>b;
for(j=0;j<s;j++)
{if(b==na[j].getnum())
{ cout<<"查询的人信息如下:\n";
cout<<"姓名\t"<<"学号\t"<<"性别\t"<<"物理\t";
cout<<"英语\t"<<"数学\t"<<"导论\t"<<"C成绩\t"<<"总分\t"<<endl;
cout<<na[j].name<<"\t"<<na[j].num<<"\t"<<na[j].sex<<"\t"<<na[j].physics<<"\t"<<na[j].English<<"\t"<<na[j].math;
cout<<"\t"<<na[j].computer<<"\t"<<na[j].c<<"\t"<<na[j].total<<endl;}
}