读书人

异常1error C2440: “=”: 无法从“co

发布时间: 2012-02-12 17:16:33 作者: rapoo

错误1error C2440: “=”: 无法从“const char [10]”转换为“char [10]”e:\vsproject\2_12\2_12
请大家帮忙看一下
# include <iostream>
using namespace std;
union student {
int nob;
char name[10];
};
int main (){
student s2;
s2.nob=02;
s2.name="qinxueda ";
cout <<"the number of s2 is "<<s2.nob<<" \n"<<"and the name of s2 is "<<s2.name;
getchar();
}

[解决办法]
用strcpy试试?
[解决办法]
数组名是个常量(不是变量)不能赋值。
这样:

C/C++ code
# include <iostream>using namespace std;union student {int nob; char *name;};int main (){student s2;s2.nob=02;s2.name="qinxueda ";cout <<"the number of s2 is "<<s2.nob<<" \n"<<"and the name of s2 is "<<s2.name;getchar();} 

读书人网 >C++ Builder

热点推荐