How To Get Size Of Vector C++
Vector of vectors, how to find size?
How would I edit this to prove the size of the inner vector? (Not sure if that is technically correct. Delight correct me if it's not)
| |
Last edited on
To become the size of vector test[x] you do exam[x].size() .
| |
Squeamish to see you use C++xi elements!
| |
In your lawmaking there shall exist
for (int y = 0; y < test[ten].size(); ++y)
instead of
for (int y = 0; y < test.size(); ++y)
First when you declare vectors of vectors do it like so vector< vector<int> > // Hint: Notice the space between the >'s
| |
You lot accept to remember that each element of the first vector is a vector itself and has all the functionality of a normal vector. So you but demand to tell the programme which chemical element you want to admission the size of and and then use the size command.
EDIT: A ameliorate example based on your code
| |
DOUBLE EDIT: Gezz I'm always to wearisome :(
Terminal edited on
| Zereo wrote: |
|---|
First when you declare vectors of vectors do information technology like so vector< vector<int> > // Hint: Notice the space betwixt the >'s |
Is this a stylistic suggestion? Because in C++11 it'south not an error to non use spaces here.
@Zereo
First when you declare vectors of vectors do it like and then vector< vector<int> > // Hint: Discover the space between the >'s
Why shall it exist done as you showed?
*it is not an mistake to exclude the space.
I'1000 in the midst of the Brain Trust! Thanks people for all the answers =).
@Catfish3 - I'thou learning from a C++xi updated book then yeah I'm up with the times! Unless that's sarcasm, and so =(. Thanks for the code instance. Yours and vlad's helped me figure out how to fix up iterators instead. And Peter87 nudged on that.
@Zereo - Aye the book warned me nearly the spacing, but it refers to older compilers. Appreciate the explanation, hits the nail in the coffin.
Last edited on
Is this a stylistic proposition? Because in C++xi it's not an error to non apply spaces hither.
*information technology is not an error to exclude the infinite.
Why shall it be done as you showed?
Pre C++xi it is a error though so might also cover your corners. It is a error because Pre C++xi the compiler mistook the two >>'due south to hateful the >> operator.
Also I guess information technology doesn't have to exist done as shown but a lot of people don't accept C++11 compilers and information technology would be in error for them.
Final edited on
If you use any C++xi lawmaking you can assume all your lawmaking need not worry about C++03 anymore.
That is true LB, then I guess the proper mode of phrasing what I said should take been "Exist warned though that if you lot are not using C++eleven y'all demand to declare information technology like and so" instead of "you should declare information technology similar so". My mistake for miss diction it.
@Zereo
Pre C++11 it is a fault though so might every bit well cover your corners. It is a error because Pre C++11 the compiler mistook the two >>'s to mean the >> operator
It is not serious because using of '>" is not uniform with the previous standard also in some other cases. So there is no whatever sense to do what you suggested.
Adjacent time practise not give bad advices.
@ Olysold: No sarcasm, I'm genuinely excited when I come across people write C++eleven code.
Next time practise not give bad advices.
Ummm... I already admitted I probably phrased it wrong, only I don't run across how telling someone that vector<vector<int>> tin be in error for older compilers is giving bad advice.
Besides accept no idea what you are trying to say past
Information technology is not serious because using of '>" is not compatible with the previous standard also in some other cases. And then there is no whatsoever sense to exercise what y'all suggested.
#Catfish3 - Awesome. Hopefully that's enough to depict you into my threads in the future when I ask questions.
Also have no idea what y'all are trying to say by
It is not serious because using of '>" is non compatible with the previous standard also in some other cases. So there is no any sense to practise what you suggested.
I said very clear that at that place are other incompatibiles of using < and > in specifying template arguments between the previous and the current C++ Standards.
Oh ok now I understand.
And sorry if I sounded rude I just don't really like to be told that I'm giving bad advice when in fact I did no such thing. Particularly in that manner. Anyways just wanted to say sorry.
Topic archived. No new replies allowed.
How To Get Size Of Vector C++,
Source: https://www.cplusplus.com/forum/beginner/99123/
Posted by: lewisfran1950.blogspot.com

0 Response to "How To Get Size Of Vector C++"
Post a Comment