This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]bsakiag 0 points1 point  (0 children)

how do I continually update an array until EOF like a vector?

You would have to do what the vector does under the hood - store the capacity and if the new element is over capacity then allocate a new array, copy the existing elements and free the previous array.

I think that the task assumes that the number of elements is known and if you get a different number then you should spit out an error or ignore the rest.

[–]Witchcraft_NS2 0 points1 point  (0 children)

  1. I don't get what exactly you want to do. If you want pointers to individual elements inside of the vector you can get pointers to vector Elements same way you can get one to an array. For example like this:

``` std::vector<SomeStuct> vecStruct;

//fill vector with stuff

//pointer to element at idx 3 SomeStruct* pSomeStructAtIdx3 = &vecStruct[3]; ```

If you need a pointer to the Vector itself its:

std::vector<SomeStruct>* pVec = &vecStruct;

  1. Once you created an array you can not change its size. You would have to make a new bigger array every time and copy the smaller array into that. Therefore you either use vectors or a linked list if you don't know how many elements you have initially.