当可输入的最大数量为1000时,如何将数组限制为仅输入多个值的大小?

时间:2014-11-20 20:52:43

标签: c++ arrays function

#include <iostream>

using namespace std;

void displayListValues(int Array[], int Max)

   {
        int counter = 0;
        for (int i = 0; i < Max; i++)
        {
            cout << counter << " = " << Array[i] << endl;
            counter++;
        }
    }

void main()
   {
        const int Max = 1000;
        int Array[Max];  // this is where I couldn't figure out what to change so the array isn't so huge
        int counter = 0;
        cout << "Enter Numbers. If finished, enter a negative number to continue" << endl;
        do
        {
            cin >> Array[counter];
            if (Array[counter] < 0)
                break;

        } while (counter < Max);
        displayListValues(Array, Max);
    }

详细信息详细信息,任何帮助都很棒!!!多谢你们!!!! :D:D:D 我不知道还有什么要包括在这里,因为它一直说我的帖子主要是代码。我为帖子底部的这种荒谬的胡言乱语道歉。

1 个答案:

答案 0 :(得分:1)

简短的回答是你做不到的。一旦定义,C / C ++数组就是固定大小。

答案很长,你需要使用数组以外的东西。您应该使用std::vector,其行为类似于数组,但可以调整大小。

相关问题