# include "stdafx. H" #include #include using namespace std; Int main () { //vector Vit. First define the empty vector error that is not value mistakes Vector Vit (5, 1); Vector : : iterator vi;
Vi=vit. The begin (); Vit. Push_back (2); //and it would be an error Vi++;
system("pause"); Return 0; } , well, I am vs2015 current environment, on the Internet to check the iterator articles are said by + + on the point to the next element, but run by vi++ will be submitted to the Expression: vector iterator not incrementable) Error iterator is increasing, why is this so?
CodePudding user response:
Vit. Push_back (2) and vi=vit. The begin () substituted position would not be wrong
CodePudding user response:
Question reason: because you start allocated a capacity of 5, the vector of the initial value is 1, you get the iterator memory address, then you end a value, so the compiler will handle: all copies of the original values, to find a space in the address, will copy with the new value to the new space, this time, what are you doing with the previous address iterator + +, affirmation is to collapse, operation is the address you have no legal power to give you so operation, could you also maybe in Linux platform can make up for the past,