and also if you don't know the size of a data container...
example
Code:
#include <iostream>
#include <vector> // a must for vector use
using namespace std;
int main()
{
vector<int> iVector; // you have to specify the vector type by a class or a structure
int answer;
int temp;
cout<<"How many numbers do you want to enter? ";
cin>>answer;
for(int i=0; i < answer; i++)
{
answer--;
cout<<answer<<" Enter a number: "; // display how many numbers the user has left to enter
cin>>temp;
iVector.push_back(temp);
// this is magic... the temporary integer is pushed onto the back of the vector...and given a location in that vector, which you can access using iVector[anumber]
}
return0;
}
i prefer using vectors over arrays any day...
Only thing I hate doin, though, is that to access an object of a vector class (ex. iVector.erase()) you have to create a vector iterator that points to a location in the vector
ex.
Code:
class aClass
{
public:
int number;
}
aClass theClass;
vector<aClass> theClassV;
vector<aClass>::iterator theClassVIterator;
for(int i=0;i<=3;i++)
{
theClass[i].number=i;
theClassV.push_back(theClass);
}
// 0 1 2
// so now theClassV vector holds {theClass, theClass, theClass}
// at the storage spaces 0, 1, 2
// If i wanted to delete what was at location 1 I would have to do this...
for(i=0;i<=2;i++)
{
theClassVIterator++;
}
theClassV.erase(theClassVIterator);
this is the only way ive found how to make the iterator the position of the vector you want...there probably is a pro somewhere around here who can be sure...