c++ 数组错误的只使用常量表达式在数组中编制索引 解决

题目描述

用vs编写c++的时候,总是有关于数组的一个问题,麻烦各位大牛帮忙看一下

题目来源及自己的思路

相关代码

include <iostream>

include <iomanip>

using namespace std;

int main( )
{

const int arry = 200;
int Fibonacci[arry] =
{
    1, 1
};
int n;
cin >> n;
for (int i = 2; i < n; i++)
{
    Fibonacci[i] = Fibonacci[i - 2] + Fibonacci[i - 1];
}
for (int j = 1; j <= 20; j++)
{
    cout << setw(6);
    cout << Fibonacci[j - 1];
    cout << ((j % 5)? "" : "\n");
}
cout << endl;
system("pause");
return 0;

}

你期待的结果是什么?实际看到的错误信息又是什么?

错误为:
C26482 Only index into arrays using constant expressions (bounds.2)
C26446 Prefer to use gsl::at() instead of unchecked subscript operator (bounds.4)

阅读 3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题