error C2440: '=' : cannot convert from 'char [8]' to 'char [20]'
1个回答
展开全部
//char 数组不支持=运算符,需要使用strcppy(des, src);函数,头文件#include<cstring>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
struct Student
{
int num;
char name[20];
float score[3];
};
int main()
{
void print(Student);
Student stu;
stu.num = 12345;
strcpy(stu.name, "Li Fang");
stu.score[0] = 67.5;
stu.score[1] = 89;
stu.score[2] = 78.5;
print(stu);
return 0;
}
void print(Student stu)
{
cout << stu.num << " " << stu.name << " " << stu.score[0] << " " << stu.score[1] << " " << stu.score[2] << endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询