why most people use vector instead of deque?
Because this is what they have been taught.
vector and deque serve slightly different purposes. They can be used as just a container of objects, if that's all you need. When you learn C ++ programming, that’s all most people need — a bucket to throw away material, get material, and go through.
When StackOverflow is asked a question like “which container should I use by default”, the answer is almost always vector . The question is usually asked from the context of teaching a C ++ program, and at the moment when the programmer asks such a question, they still do not know what they do not know. And a lot of them still do not know. So, we (StackOverflow) need a container that fits almost any need better or worse, can be used in almost any context and does not require the programmer to ask all the right questions before landing on something that comes close to the right answer . In addition, the standard recommends the use of vector . vector not suitable for all purposes, and in fact, deque better than vector for many common applications - but for a programmer-programmer this is not much better than we should vary from standard tips to beginners with C ++ programmers, so StackOverflow lands on vector .
Having studied the basics of syntax and, let's say, C ++ programming strategies, programmers are divided into two branches: those who study more and write better programs, and those who do not. Those who do not do this will forever remain on vector . I think many programmers fall into this camp.
Rare programmers who try to go beyond this stage begin to ask other questions - questions like you asked here. They know that there are many that they do not yet know, and they want to start figuring out what these things are. They quickly (or less quickly) discover that, choosing between vector and deque , some of the questions they did not think to ask before are the following:
- Do I need a memory to be funny?
- Do I need to avoid a lot of redistribution?
- Do I need to keep valid iterators after insertion?
- Do I need my collection to be compatible with some ancient C-like function?
Then they really start thinking about the code they write, discover even more material that they don’t know, and the rhythm continues ...