JCG*_*CGM 1 c++ containers c++11
在下面的代码中,迭代器指向的值对于最后一个元素和倒数第二个元素是相同的。
#include <iostream>
#include <set>
using namespace std;
int main()
{
set<int> s1 = {4,3,2,5,1};
set<int>::iterator i;
i = s1.end();
cout << *i << endl; // 5
i--;
cout << *i << endl; // 5
cout << *s1.end() << endl; // 5
cout << *(--s1.end()) << endl; // 5
return 0;
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,结束元素指向的值应该为空。为什么会这样?