请教各位,我想从for语句中读出变量来!
#include <stdio.h>#include <iostream>
int main()
{
int sum=0;
for (int val=1; val <=10; ++val)
std::cout << "now, the val is "<< val << std::endl;
sum +=val;
// while (val <=10){
// sum+=val;
// ++val;
// }
std::cout <<"sum of 1 to 10 inclusive is:"
<<sum <<std::endl;
return 0;
}
提示信息是:
In function 'int main()':
[Error] name lookup of 'val' changed for ISO 'for' scoping [-fpermissive]
[Note] (if you use '-fpermissive' G++ will accept your code)