error C2664: 'strcpy' : cannot convert parameter 1 from 'class
c++错误为;errorC2664:'strcpy':cannotconvertparameter1from'classstd::basic_string<char,st...
c++
错误为;
error C2664: 'strcpy' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
这是函数:
void alterdate(char *p,struct student *stu,int flag)//修改数据函数的定义和实现
{
int i;
struct student temp;
if(flag==1)
{
strcpy(temp.name,p);
for(i=0;i<count;i++)
{
if(strcmp(stu[i].name,temp.name)==0)
{
cout<<"请从新输入"<<stu[i].name<<"的数据"<<endl;
cin>>stu[i].number>>stu[i].math>>stu[i].english;
stu[i].total=stu[i].math+stu[i].english;
stu[i].aver=stu[i].total/2;
}
}
}
else
{
strcpy(temp.number,p);
for(i=0;i<count;i++)
{
if(strcmp(stu[i].number,temp.number)==0)
{
cout<<"请从新输入学号为"<<stu[i].number<<"的数据"<<endl;
cin>>stu[i].name>>stu[i].math>>stu[i].english;
stu[i].total=stu[i].math+stu[i].english;
stu[i].aver=stu[i].total/2;
}
}
}
}
在主函数中定义了一个结构体为:
struct student{
public:
int classroom;
float math,english,total,aver;
char name[30],number[20];
};
调用函数的语句为cout<<"请输入姓名:";
cin>>name;
alterdate(name,stu,1);
break;
这里的stu是结构体的一个数组; 展开
错误为;
error C2664: 'strcpy' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
这是函数:
void alterdate(char *p,struct student *stu,int flag)//修改数据函数的定义和实现
{
int i;
struct student temp;
if(flag==1)
{
strcpy(temp.name,p);
for(i=0;i<count;i++)
{
if(strcmp(stu[i].name,temp.name)==0)
{
cout<<"请从新输入"<<stu[i].name<<"的数据"<<endl;
cin>>stu[i].number>>stu[i].math>>stu[i].english;
stu[i].total=stu[i].math+stu[i].english;
stu[i].aver=stu[i].total/2;
}
}
}
else
{
strcpy(temp.number,p);
for(i=0;i<count;i++)
{
if(strcmp(stu[i].number,temp.number)==0)
{
cout<<"请从新输入学号为"<<stu[i].number<<"的数据"<<endl;
cin>>stu[i].name>>stu[i].math>>stu[i].english;
stu[i].total=stu[i].math+stu[i].english;
stu[i].aver=stu[i].total/2;
}
}
}
}
在主函数中定义了一个结构体为:
struct student{
public:
int classroom;
float math,english,total,aver;
char name[30],number[20];
};
调用函数的语句为cout<<"请输入姓名:";
cin>>name;
alterdate(name,stu,1);
break;
这里的stu是结构体的一个数组; 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询