I'm practicing std::deque
, specifically iterators
I tested the end
iterator. like this:
std::deque<const char*> wup {"how","are","you","doing","today?"};
std::deque<const char*>::iterator it = wup.end();
Then, I want to print it
, and I know that the end iterator is empty.
Then I try to use 2 cout
statements to print the content of it
: one of them before --it
and another after --it
But if I write a cout
before --it
, the last cout
does not appear in the output.
Something like this:
std::deque<const char*> wup {"how","are","you","doing","today?"};
std::deque<const char*>::iterator it = wup.end();
std::cout<<"Before --it: "<<*it<<std::endl;// okay, it works good | and finishes console
--it;
std::cout<<"After --it: "<<*it<<std::endl;// I do not know why it does not appear.
Output:
Before --it: Process returned 0 (0x0) execution time : 0.010 s Press ENTER to continue.
Where did I make a mistake ?
if dereferencing an iterator is wrong ...
why this case, cuts the output-stream without any exception
Thanks a lot.
tested on:
OS: Ubuntu 16.01
compiler: g++ version: 5.3.1
IDE: code::blocks 16.01
Edit: I found this note in /reference/en/cpp/container/map/erase.html :
The iterator pos must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferencable) cannot be used as a value for pos.
I think this is real reason for, why ... .
my native language is not English, so excuse me, if you see some mistake