异常1error C2440: “初始化”: 无法从“const char [2]”转换为“char”c:\documents and settings\
错误1error C2440: “初始化”: 无法从“const char [2]”转换为“char”c:\documents and settings\
错误提示如题
以下是代码
求改正
#include<iostream>
#include <string>
using namespace std;
struct student
{
int studentID;
char name[20];
char sex;
};
int main()
{
student std[2]={{2001,"王母","M"},{2002,"玉帝","F"}};
for(int i=0;i<2;i++)
cout<<std[i].studentID<<" "<<std[i].name<<" "<<std[i].sex<<endl;
}
------解决方案--------------------
错误提示如题
以下是代码
求改正
#include<iostream>
#include <string>
using namespace std;
struct student
{
int studentID;
char name[20];
char sex;
};
int main()
{
student std[2]={{2001,"王母","M"},{2002,"玉帝","F"}};
for(int i=0;i<2;i++)
cout<<std[i].studentID<<" "<<std[i].name<<" "<<std[i].sex<<endl;
}
------解决方案--------------------
- C/C++ code
#include<iostream> #include <string> using namespace std; struct student { int studentID; char name[20]; char sex; }; int main() { student std[2]={{2001,"王母",'M'},{2002,"玉帝",'F'}}; // sex 是 char 类型 用 单引号 for(int i=0;i<2;i++) cout<<std[i].studentID<<" "<<std[i].name<<" "<<std[i].sex<<endl; }
------解决方案--------------------
- C/C++ code
student std[2]={{2001,"王母",'M'},{2002,"玉帝",'F'}};//M、F应该用单引号