I am trying to access the element of a vector using the iterator. But I get strange outputs.
std::vector ivec{ 7, 6 , 8, 9} ;
std::vector
end
iterators are not iterators that you can de-reference. They point past the last element into the container. There's a good reason why this needs to be true; but long and short, the end
iterator does not actually point to any element. If you want the last element, you need to decrement the end iterator.