首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

异常1error C2440: “=”: 无法从“const char [10]”转换为“char [10]”e:\vsproject\2_12\2_12

2012-02-12 
错误1error C2440: “”: 无法从“const char [10]”转换为“char [10]”e:\vsproject\2_12\2_12请大家帮忙看一

错误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();} 

热点排行