|
-
February 17th, 2016, 06:09 AM
#1
How can I get the pre-last item of a map?
Hello again,
my code runs each item of a map and I would like to stop before the last item is reached. I would be thrilled if anybody can explain...
Code:
typedef map<int, int> M;
typedef M::iterator It;
M m;
m[1] = 1;
m[2] = 2;
m[3] = 3;
for (It it=m.begin(); it != m.end(); ++it) {
if (it == m.end() -1) // ?
cout << "pre-last item found: " << it->second; // result 2
}
sincerly,
Necip
a bit more about me on processing8.wordpress.com
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|