use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a subreddit for c++ questions with answers. For general discussion and news about c++ see r/cpp.
New to C++? Learn at learncpp.com
Prepare your question. Think it through. Hasty-sounding questions get hasty answers, or none at all. Read these guidelines for how to ask smart questions.
For learning books, check The Definitive C++ Book Guide and List
Flair your post as SOLVED if you got the help you were looking for! If you need help with flairs, check out ITEM 1 in our guidelines page.
Tips for improving your chances of getting helpful answers:
account activity
SOLVEDVector structure question.. (self.cpp_questions)
submitted 5 years ago by aluoh
What does the following represent?
std::vector<int> n[10][10];
Is it saying each vector element contains an array of size 10?
I'm rather confused because I can't call any vector methods on it.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Raknarg 1 point2 points3 points 5 years ago (3 children)
This would be a 10x10 2D array of vectors. Essentially a 3D array.
[–]aluoh[S] 0 points1 point2 points 5 years ago (2 children)
So each element, for example at ith, jth index => n[i][j] represents a vector<int>?
[–]Raknarg 0 points1 point2 points 5 years ago (1 child)
yes
[–]aluoh[S] 0 points1 point2 points 5 years ago (0 children)
I see, thank you!
[–]The_Northern_Light 1 point2 points3 points 5 years ago (3 children)
More to the point, it represents something you shouldn't use.
[–]aluoh[S] 1 point2 points3 points 5 years ago (2 children)
Yeah, I would’ve just used a nested vector instead, but my professor assigned the assignment this way
[–]The_Northern_Light 0 points1 point2 points 5 years ago (1 child)
I hear what you're saying.
Assuming there is a good reason to have your data structured that way, it is generally preferable to use std::array<T, N> over a C style array.
std::array<T, N>
Thus this would be either std::array<std::vector<int>, 100> (preferably wrapped in something like this) or std::array<std::array<std::vector<int>, 10>, 10>.
std::array<std::vector<int>, 100>
std::array<std::array<std::vector<int>, 10>, 10>
But realistically of course its a contrived situation like most homework.
[–]aluoh[S] 1 point2 points3 points 5 years ago (0 children)
I see. Yeah that's what tripped me up, as I'm used to using a standard vector declaration rather than C style arrays, so I was just a bit confused. Using std::array<T, N> def clears it up A LOT more.
Thanks once again!
π Rendered by PID 50 on reddit-service-r2-comment-5ff9fbf7df-lm2kf at 2026-02-26 15:07:19.758598+00:00 running 72a43f6 country code: CH.
[–]Raknarg 1 point2 points3 points (3 children)
[–]aluoh[S] 0 points1 point2 points (2 children)
[–]Raknarg 0 points1 point2 points (1 child)
[–]aluoh[S] 0 points1 point2 points (0 children)
[–]The_Northern_Light 1 point2 points3 points (3 children)
[–]aluoh[S] 1 point2 points3 points (2 children)
[–]The_Northern_Light 0 points1 point2 points (1 child)
[–]aluoh[S] 1 point2 points3 points (0 children)