gpt4 book ai didi

调用 scanf() 会出现错误 "ISO C++ forbids cast to non-reference type used as lvalue"

转载 作者:行者123 更新时间:2023-11-30 18:22:36 25 4
gpt4 key购买 nike

我有这个代码:

int* read(){
int i,num,array[11];
printf("enter a integer value between 1 & 10: ");
scanf("%i",&num);
while(!(num>0&&num<11)){
read() ;
}

if(num>0&&num<11){
printf("enter %i integers now: ",num);
for(i=0;i<num;i++)
scanf("%i",*array++);//LINE 19 is here..........

*array=0;
}
return array;
}

当我尝试调用此函数时,它显示以下编译器错误:

[Error] C:\Users\seeker-PC\Documents\C-Free\Projects\n\Untitled12.cpp:19: error: ISO C++ forbids cast to non-reference type used as lvalue
[Error] C:\Users\seeker-PC\Documents\C-Free\Projects\n\Untitled12.cpp:19: error: non-lvalue in assignment

您能解释一下出了什么问题吗?

最佳答案

scanf("%i",*array++);

这句话毫无意义。您的意思可能是:

scanf("%i", &array[i]);

关于调用 scanf() 会出现错误 "ISO C++ forbids cast to non-reference type used as lvalue",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18598070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com