Help meh :D

Oct 22, 2011 at 4:56pm
Hello again everyone,
i came on here today to ask a question, how do i write more data to an array? if you dont know what i mean ill explain..

here i am just casually declaring an array..
int a[] = {1, 2, 3, 4, 5};

now.. i want to be able to do this..
int a[] = {};

and then afterwards add them in so what would the code be?
Oct 22, 2011 at 5:16pm
closed account (zb0S216C)
The length of an array must be known at compile time. The length cannot be defined at a later time. If you insist on creating an array at some other point, use DMA. Alternatively, the more preferred way is the std::vector[1, Link]. By the way, the second array declaration is invalid. The compiler won't be able to determine the length of the array.

References:
[1]http://www.cplusplus.com/reference/stl/vector/


Wazzak
Last edited on Oct 22, 2011 at 5:18pm
Oct 22, 2011 at 5:19pm
Damnit, so what do you recon i should do?
Oct 22, 2011 at 6:17pm
closed account (zb0S216C)
Like I said, either use DMA or std::vector. Either one will work, but DMA has its risks. Use DMA if the array will stay the same length, or use std::vector if the array's length will change dynamically.

Wazzak
Last edited on Oct 22, 2011 at 6:21pm
Topic archived. No new replies allowed.