Ti ho già dato ben due soluzioni che non richiedono std::vector...
Amaro C++, il gusto pieno dell'undefined behavior.
Regole del Forum