# Vectors of arrays

This topic is 5038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm obviously missing something obvious, but how does one go about doing this: If I have a vector of ints, for example, I can use vector<int> myVec; myVec.push_back(1); If I have a vector of arrays of ints, how do I add an element: vector<int[2]> myVec; myVec.push_back(??) Thanks, Jim.

##### Share on other sites
Quote:
 Original post by JimPriceIf I have a vector of arrays of ints, how do I add an element:vector myVec;myVec.push_back(??)

Its not possible, the closest you'll get to that with vector is something like this:

typedef std::vector<int> vec_of_ints;typedef std::vector< vec_of_ints > vec2d_of_ints;vec2d_of_ints::size_type cols = /* some-size */vec_of_ints::size_type rows = /* some-size */vec2d_of_ints v(cols, vec_of_ints(rows, 0));

there are other ways of constructing it but you can't have a vector of C-style arrays only vector of vectors (or vector of some other container).

but its not really a nice way to handle multidimensional arrays, you might wont to consider this

Ta very much

##### Share on other sites
[off-topic]

snk_kid, you got a 1337 rating [smile]
I don't dare to rate you up now :)

Thermo

##### Share on other sites
He is 1337! :)

Could you not just use pointers? Such, creat an array and use a pointer to that array as the datatype for the vector? Would that work, or I am completely wrong?

##### Share on other sites
Quote:
 Original post by NietsnieHe is 1337! :)Could you not just use pointers? Such, creat an array and use a pointer to that array as the datatype for the vector? Would that work, or I am completely wrong?
the problem is, once you retrieve that pointer from the vector, how large is your array?

##### Share on other sites
Quote:
 Original post by NietsnieHe is 1337! :)
Actually he's more than 1337 now (1341). He's like ultra 1337.

In fact if they were after more admins, snk would be the man I'd recommend for the job.

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 29
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631740
• Total Posts
3001962
×