Variable subscripted array

Jul 14, 2011 at 9:47pm
Quick question, kinda. Can you make arrays without a set subscript. For example, let's say I wanna make a program that allows a user to enter all there employees, but you don't know how many employees they have. So you'd have to make the program with a variable subscript for the array. Is this possible, and if so, how do you do it, and then how do you manipulate/display it.
Jul 14, 2011 at 9:52pm
Yes, this is called a vector.

1
2
vector<Employee> employees;
employees.push_back(Employee(...));


With push_back you can add a new element at the end and size() gives you the number of elements in the vector. Element access works like with a fixed array.
See also: http://www.cplusplus.com/reference/stl/vector/
Jul 14, 2011 at 11:15pm
Ok I've heard about vectors but have not yet gotten there with my programming. What exactly are vectors?
Jul 14, 2011 at 11:30pm
They're dynamic arrays, there isn't much more to it. Read the reference above if you want any more details.
Last edited on Jul 14, 2011 at 11:44pm
Topic archived. No new replies allowed.