Quantcast
Channel: How can I get the penultimate element in a list? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

How can I get the penultimate element in a list?

$
0
0

I have a std::list<double> foo;

I'm using

if (foo.size() >= 2){    double penultimate = *(--foo.rbegin());}

but this always gives me an arbitrary value of penultimate.

What am I doing wrong?


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>