当您引用 cppreference 时,你会发现这个:
Returns an iterator to the element following the last element of the
container. This element acts as a placeholder; attempting to access it
results in undefined behavior.
然后我运行以下代码:
std::set<int> s {1, 2, 3};
cout << *s.end() << endl;
输出是:3,为什么?
What will be returned from std::set.end() exactly in c++?
它返回:
an iterator to the element following the last element of the container.
注意:
This element acts as a placeholder; attempting to access it results in undefined behavior.
The out put is: 3, why?
因为:
attempting to access it results in undefined behavior.
因此它可以做您的编译器想做的任何事情,并且返回 3 是您的编译器显然想做的任何事情。