You can't use a non-const variable to create a C-style array like that. If the size of an array is not known at compile time, you need to use a container that automatically resizes itself, such as a vector (a vector is a 'C++ array') or allocate the array onto the heap with the
new operator
CODE
#include <iostream>
#include <vector>
int main()
{
using namespace std;
//The vector resizes itself automatically,
// depending how many elements you add.
vector<int> my_vec;
int num_items;
cout << "How many items of data? ";
cin >> num_items;
for(int i(0); i < num_items; ++i)
{
int temp;
cout << "Enter a number: ";
cin >> temp;
//push_back adds 'temp' to the end, increasing the
// size of the vector by 1.
my_vec.push_back(temp);
}
}
This post has been edited by Bench: 30 Aug, 2007 - 07:44 AM