c++关于error c2664的
程序如下#include<iostream.h>#include<string.h>#include<iomanip.h>structstudent{charname[2...
程序如下
#include<iostream.h>
#include <string.h>
#include <iomanip.h>
struct student
{
char name[20];
char xuehao[20];
float score[3];
float aver;
};
void input (student stud[],int n)
{
for (int j=0;j<n;j++)
{ cout<<"请输入第"<<j<<"个学生的三门成绩 ";
for (int i=0;i<3;i++)
cin<<stud.score[i];
cout <<endl;
}
}
void output(student stud[] ,int n)
{
cout <<setw(10)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"c++成绩"<<setw(10)<<"英语成绩"<<setw(10)<<"数学成绩"<<setw(10)<<"平均成绩";
for (int j=0;j<n;j++)
{
cout <<setw(10)<<stud[j].name<<setw(10)<<stud[j].xuehao;
for (int i=0;i<3;i++)
cout<<setw(10) <<stud[j].score[i];
cout <<endl;
}
}
void aver(student stud[],int n)
{
float sum;
for (int j=0;j<n;j++)
{
for (int i=0;i<3;i++)
sum+=stud[j].score[i];
stud[j].aver=sum/n;
}
}
void paixu (student stud[],int n)
{
for (int i=0;i<n;i++)
{
int k=i;
for (int j=k+1;j<n;j++)
if (stud[k].aver<stud[j].aver) k=j;
if (k!=i)
{
char name,xuehao;
strcpy(name ,stud[k].name);
strcpy(stud[k].name,stud[i].name);
strcpy( stud[i].name,name);
strcpy (xuehao,stud[k].xuehao);
strcpy (stud[i].xuehao,stud[k].xuehao);
strcpy (stud[i].xuehao,xuehao);
for (int t=0;t<3;t++)
{
float s;
s=stud[k].score[t];
stud[k].score[t]=stud[i].score[t];
stud[i].score[t]=s;
}
}
}
}
void main()
{
void input (student stud[],int n);
void output(student stud[] ,int n);
void aver(student stud[],int n);
void paixu (student stud[],int n);
student stud[]={{"Aa","20201",0,0 ,0,0},{"Bb","20202",0,0 ,0,0},{"Cc","20203",0,0 ,0,0},{"Dd","20204",0,0 ,0,0}};
input(stud,4);
paixu(stud ,4);
output (stud ,4);
}
E:\aaa学习资料\c++\实验八\lx0804.cpp(57) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
都是这个问题 展开
#include<iostream.h>
#include <string.h>
#include <iomanip.h>
struct student
{
char name[20];
char xuehao[20];
float score[3];
float aver;
};
void input (student stud[],int n)
{
for (int j=0;j<n;j++)
{ cout<<"请输入第"<<j<<"个学生的三门成绩 ";
for (int i=0;i<3;i++)
cin<<stud.score[i];
cout <<endl;
}
}
void output(student stud[] ,int n)
{
cout <<setw(10)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"c++成绩"<<setw(10)<<"英语成绩"<<setw(10)<<"数学成绩"<<setw(10)<<"平均成绩";
for (int j=0;j<n;j++)
{
cout <<setw(10)<<stud[j].name<<setw(10)<<stud[j].xuehao;
for (int i=0;i<3;i++)
cout<<setw(10) <<stud[j].score[i];
cout <<endl;
}
}
void aver(student stud[],int n)
{
float sum;
for (int j=0;j<n;j++)
{
for (int i=0;i<3;i++)
sum+=stud[j].score[i];
stud[j].aver=sum/n;
}
}
void paixu (student stud[],int n)
{
for (int i=0;i<n;i++)
{
int k=i;
for (int j=k+1;j<n;j++)
if (stud[k].aver<stud[j].aver) k=j;
if (k!=i)
{
char name,xuehao;
strcpy(name ,stud[k].name);
strcpy(stud[k].name,stud[i].name);
strcpy( stud[i].name,name);
strcpy (xuehao,stud[k].xuehao);
strcpy (stud[i].xuehao,stud[k].xuehao);
strcpy (stud[i].xuehao,xuehao);
for (int t=0;t<3;t++)
{
float s;
s=stud[k].score[t];
stud[k].score[t]=stud[i].score[t];
stud[i].score[t]=s;
}
}
}
}
void main()
{
void input (student stud[],int n);
void output(student stud[] ,int n);
void aver(student stud[],int n);
void paixu (student stud[],int n);
student stud[]={{"Aa","20201",0,0 ,0,0},{"Bb","20202",0,0 ,0,0},{"Cc","20203",0,0 ,0,0},{"Dd","20204",0,0 ,0,0}};
input(stud,4);
paixu(stud ,4);
output (stud ,4);
}
E:\aaa学习资料\c++\实验八\lx0804.cpp(57) : error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
都是这个问题 展开
1个回答
展开全部
#include<iostream.h>
#include <string.h>
#include <iomanip.h>
struct student
{
char name[20];
char xuehao[20];
float score[3];
float aver;
};
void input (student stud[],int n)
{
for (int j=0;j<n;j++)
{
cout<<"请输入第"<<j<<"个学生的三门成绩 ";
for (int i=0;i<3;i++)
cin>>stud[j].score[i]; //少了j,写错>>
cout <<endl;
}
}
void output(student stud[] ,int n)
{
cout <<setw(10)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"c++成绩"<<setw(10)<<"英语成绩"<<setw(10)<<"数学成绩"<<setw(10)<<"平均成绩";
for (int j=0;j<n;j++)
{
cout <<setw(10)<<stud[j].name<<setw(10)<<stud[j].xuehao;
for (int i=0;i<3;i++)
cout<<setw(10) <<stud[j].score[i];
cout <<endl;
}
}
void aver(student stud[],int n)
{
float sum;
for (int j=0;j<n;j++)
{
for (int i=0;i<3;i++)
sum+=stud[j].score[i];
stud[j].aver=sum/n;
}
}
void paixu (student stud[],int n)
{
for (int i=0;i<n;i++)
{
int k=i;
for (int j=k+1;j<n;j++)
if (stud[k].aver<stud[j].aver)
k=j;
if (k!=i)
{
char name[20],xuehao[20]; //写成这样
strcpy(name ,stud[k].name);
strcpy(stud[k].name,stud[i].name);
strcpy( stud[i].name,name);
strcpy (xuehao,stud[k].xuehao);
strcpy (stud[i].xuehao,stud[k].xuehao);
strcpy (stud[i].xuehao,xuehao);
for (int t=0;t<3;t++)
{
float s;
s=stud[k].score[t];
stud[k].score[t]=stud[i].score[t];
stud[i].score[t]=s;
}
}
}
}
void main()
{
void input (student stud[],int n);
void output(student stud[] ,int n);
void aver(student stud[],int n);
void paixu (student stud[],int n);
student stud[]={{"Aa","20201",0,0 ,0,0},{"Bb","20202",0,0 ,0,0},{"Cc","20203",0,0 ,0,0},{"Dd","20204",0,0 ,0,0}};
input(stud,4);
paixu(stud ,4);
output (stud ,4);
}
#include <string.h>
#include <iomanip.h>
struct student
{
char name[20];
char xuehao[20];
float score[3];
float aver;
};
void input (student stud[],int n)
{
for (int j=0;j<n;j++)
{
cout<<"请输入第"<<j<<"个学生的三门成绩 ";
for (int i=0;i<3;i++)
cin>>stud[j].score[i]; //少了j,写错>>
cout <<endl;
}
}
void output(student stud[] ,int n)
{
cout <<setw(10)<<"姓名"<<setw(10)<<"学号"<<setw(10)<<"c++成绩"<<setw(10)<<"英语成绩"<<setw(10)<<"数学成绩"<<setw(10)<<"平均成绩";
for (int j=0;j<n;j++)
{
cout <<setw(10)<<stud[j].name<<setw(10)<<stud[j].xuehao;
for (int i=0;i<3;i++)
cout<<setw(10) <<stud[j].score[i];
cout <<endl;
}
}
void aver(student stud[],int n)
{
float sum;
for (int j=0;j<n;j++)
{
for (int i=0;i<3;i++)
sum+=stud[j].score[i];
stud[j].aver=sum/n;
}
}
void paixu (student stud[],int n)
{
for (int i=0;i<n;i++)
{
int k=i;
for (int j=k+1;j<n;j++)
if (stud[k].aver<stud[j].aver)
k=j;
if (k!=i)
{
char name[20],xuehao[20]; //写成这样
strcpy(name ,stud[k].name);
strcpy(stud[k].name,stud[i].name);
strcpy( stud[i].name,name);
strcpy (xuehao,stud[k].xuehao);
strcpy (stud[i].xuehao,stud[k].xuehao);
strcpy (stud[i].xuehao,xuehao);
for (int t=0;t<3;t++)
{
float s;
s=stud[k].score[t];
stud[k].score[t]=stud[i].score[t];
stud[i].score[t]=s;
}
}
}
}
void main()
{
void input (student stud[],int n);
void output(student stud[] ,int n);
void aver(student stud[],int n);
void paixu (student stud[],int n);
student stud[]={{"Aa","20201",0,0 ,0,0},{"Bb","20202",0,0 ,0,0},{"Cc","20203",0,0 ,0,0},{"Dd","20204",0,0 ,0,0}};
input(stud,4);
paixu(stud ,4);
output (stud ,4);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询