Skip to content

Commit 1e92a9e

Browse files
end()-1 equals to prev(end)
1 parent 70018ee commit 1e92a9e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

iterator_end_minus_1_prev.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
#include <iterator>
3+
#include <string>
4+
5+
//https://stackoverflow.com/questions/15578178/how-to-end-iteration-through-a-c-stdset-one-element-early
6+
7+
using namespace std;
8+
9+
int main() {
10+
string str("hello world");
11+
12+
cout << *prev(str.end()) << endl; //d
13+
cout << *(str.end()-1) << endl; //d
14+
15+
return 0;
16+
}

0 commit comments

Comments
 (0)