在输入姓名的部分出错了。error C2440: '=' : cannot convert from 'char *' to 'char [10]'
student::student(char*n,doubles1,doubles2,doubles3){if(n)name=newchar[strlen(n)+1];st...
student::student(char *n,double s1,double s2,double s3)
{
if(n) name=new char[strlen(n)+1];
strcpy(name,n);
score[0]=s1;
score[1]=s2;
score[2]=s3;
}
#include <iostream.h>
#include <string.h>
class student
{
private:
char name[10];
double score[3];
public:
student(char *n,double s1,double s2,double s3);
double avg();
void printname();
};
student::student(char *n,double s1,double s2,double s3)
{
if(n) name=new char[strlen(n)+1];
strcpy(name,n);
score[0]=s1;
score[1]=s2;
score[2]=s3;
}
double student::avg(){return (score[0]+score[1]+score[2])/3;}
void student::printname(){cout<<name;}
void main()
{
student s1("张三",90.0,78.0,66.0),s2("李四",78.0,88.0,76.0);
cout<<"学生姓名、平均成绩"<<endl;
s1.printname();
cout<<s1.avg()<<endl;
s2.printname();
cout<<s2.avg()<<endl;
} 展开
{
if(n) name=new char[strlen(n)+1];
strcpy(name,n);
score[0]=s1;
score[1]=s2;
score[2]=s3;
}
#include <iostream.h>
#include <string.h>
class student
{
private:
char name[10];
double score[3];
public:
student(char *n,double s1,double s2,double s3);
double avg();
void printname();
};
student::student(char *n,double s1,double s2,double s3)
{
if(n) name=new char[strlen(n)+1];
strcpy(name,n);
score[0]=s1;
score[1]=s2;
score[2]=s3;
}
double student::avg(){return (score[0]+score[1]+score[2])/3;}
void student::printname(){cout<<name;}
void main()
{
student s1("张三",90.0,78.0,66.0),s2("李四",78.0,88.0,76.0);
cout<<"学生姓名、平均成绩"<<endl;
s1.printname();
cout<<s1.avg()<<endl;
s2.printname();
cout<<s2.avg()<<endl;
} 展开
2个回答
展开全部
name是什么玩意?
你的声明一定是这样写的:
char name[10];
改成
char* name;
猜得对么?
你的声明一定是这样写的:
char name[10];
改成
char* name;
猜得对么?
追问
之前不知道怎么了,整个程序打进去,提问不了。所以只能放一小段。
Compiling...
myfile7.cpp
D:\vc++6.0\new12\myfile7.cpp(15) : error C2440: '=' : cannot convert from 'char *' to 'char [10]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
Error executing cl.exe.
myfile7.obj - 1 error(s), 0 warning(s)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询