解决[Error] ‘i‘ was not declared in this scope

布满荆棘的人生 2023-01-07 10:21 272阅读 0赞

解决

想必大家都遇到过这种报错
这是为什么呢?

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int sum=0;
  6. for(i=0;i<=10;i++)
  7. sum++;
  8. cout<<sum;
  9. return 0;
  10. }

这个程序就会报错[Error] ‘i’ was not declared in this scope
因为for循环变量’i’并没有定义才会导致这样
这其中的’i’可以换成任何变量名,比如’x’,‘j’,什么的
下次遇到这种错误就知道该怎么办了吧!

发表评论

表情:
评论列表 (有 0 条评论,272人围观)

还没有评论,来说两句吧...

相关阅读