回 帖 发 新 帖 刷新版面

主题:C++Builder结构体赋值出错

struct myjg
{
        char    acHm[10];
        int     iAge;
};

void __fastcall TForm1::Button2Click(TObject *Sender)
{

struct myjg jg1;
memset( &jg1, 0x00,sizeof(struct myjg));

jg1.acHm ="阿富"; //出错地方
jg1.iAge =27;

ShowMessage(IntToStr(jg1.iAge));
}
一执行就出错了:
[C++ Error] Unit1.cpp(33): E2277 Lvalue required
也就是上面出错的地方.
要是我把jg1.acHm ="阿富"; 拿掉,程序就正常执行,错在哪里呀?

回复列表 (共2个回复)

沙发

晕倒,
jg1.acHm ="阿富"; //出错地方
换成strcpy( jg1.acHm, "阿富");就可以了

板凳

建议把myjg定义为:

struct myjg
{
        AnsiString    acHm;
        int     iAge;
};

这样可把函数直接定义为:

void __fastcall TForm1::Button2Click(TObject *Sender)
{
struct myjg jg1;
jg1.acHm ="阿富";
jg1.iAge =27;
ShowMessage(IntToStr(jg1.iAge));
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册