This stuff is explained in every college-level course on operating system design and/or compiler design.
The objects in question are instantiated on the stack, and at the end of the scope, they go out of scope on the stack. The stack grows and shrinks accordingly, and because on every iteration of the loop, the same exact objects get created (and destroyed), the stack grows and shrinks by the same amount, so the same objects always end up getting instantiated at the same location on the stack.
In practice, the compiler can do some optimizations and figure out the large amount of stack each function will use, most of the time, and thus "pregrow" the stack to the large amount the function will need; but that's going a bit too far into the weeds...
This is as concise answer as I can give, without going into an entire lecture of what a stack is, etc...
Now, the other object is allocated on the heap. Focus your attention on the fact that, at the end of the loop, the object you stuffed into the vector still exists, while the "a" object gets destroyed, and you'll begin to see the difference. On each iteration of the loop the "a" object gets created, and then destroyed at the end of the loop (and get created at the beginning of the loop again), while the object you stuffed into the vector still exists.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…