I want to add an int into an array, but the problem is that I don\'t know what the index is now.
int[] arr = new int[15];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;
I fully agree with the vector way when implementing a dynamic array. However, bear in mind that STL provides you with a host of containers that cater to different runtime requirements.You should choose one with care. E.g: For fast insertion at back you have the choice between a vector and a deque.
And I almost forgot, with great power comes great responsibility :-) Since vectors are flexible in size, they often reallocate automagically to adjust for adding elements.So beware about iterator invalidation (yes, it applies as well to pointers). However, as long as you are using operator[] for accessing the individual elements you are safe.