防爆pression必须是一个可修改的L值 [英] Expression must be a modifiable L-value

查看:145
本文介绍了防爆pression必须是一个可修改的L值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有字符文本[60];

然后我在如果

if(number == 2)
  text = "awesome";
else
  text = "you fail";

和它总是说前pression必须是一个可修改的L值。

推荐答案

您不能更改文本值,因为它是一个数组,而不是一个指针。

You cannot change the value of text since it is an array, not a pointer.

无论其声明为字符指针(在这种情况下,最好将其声明为为const char *

Either declare it as char pointer (in this case it's better to declare it as const char*):

const char *text;
if(number == 2) 
    text = "awesome"; 
else 
    text = "you fail";

还是用strcpy的:

Or use strcpy:

char text[60];
if(number == 2) 
    strcpy(text, "awesome"); 
else 
    strcpy(text, "you fail");

这篇关于防爆pression必须是一个可修改的L值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆