There are a couple of ways you could do it easily. You could create a small struct and store that. Alternatively, you could have a vector of pairs.
I've written a working example using both here:
https://ideone.com/gWX2rm
Note that this add a little complexity to your sorting. The struct needs to overload the < operator, so that the sort operation knows how to compare two PancakeStats.
The pair method also needs this, but passes a lambda function as a predicate to std::sort.
A couple of std::vector notes that may have been missed
I noticed a couple of things in your vector usage.
First off, it's worth noting that unlike arrays you don't
need to know the size of the vector when you declare it. For example, you could create one without passing the people variable in your code. Vectors are expandable by their very nature. You can add to them by using the
push_back()
method.
A vector will be initially allocated
some size. This isn't in the standard and is implementation specific. When the memory reserved by a vector is exceeded, it'll resize, reserving double the size, and copy the data to the new location in memory. Worth noting that this can be expensive, so reserving size can bear a performance benefit.
Vectors have methods for accessing the first and last elements. They are
front()
and
back()
respectively.
When retrieving elements by index, it's possible to access an out of bounds index. If you use the [] operator, you'll end up with undefined behaviour. A safer method is to use the
at()
, which will throw std::out_of_range if you access an out of bounds index.