[try Beta version]
Not logged in

 
vector erase

Jun 14, 2013 at 6:39am
what will this code do?

1
2
3
4
5
6
7
8
9
10
  #include<iostream>
  #include<string>
  #include<vector>
  int main()
{
  vector<string> object;
  for(int count=0;true;count++)
  object.erase((object.begin())-count);
return 0;
}
Last edited on Jun 14, 2013 at 6:43am
Jun 14, 2013 at 7:29am
refering to this:

http://www.cplusplus.com/reference/vector/vector/erase/

An invalid position or range causes undefined behavior


as soon as count > 0 the iterator is invalid
Jun 14, 2013 at 9:58am
This code tries to abort the program.:)
Topic archived. No new replies allowed.