[Solved] Vector Subscript Out of Range C++ [closed]


The problem is that in the DeckOfCards class, the deck vector is never added to, so it’s empty.

In the constructor, assign newDeck to deck:

deck = newDeck;

There is also another problem in the constructor: You declare newDeck to contain 52 entries, but then you use push_back to add new entries to the vector. This increases the size of the vector as those entries are added after the 52 entries you declared it to initially have.

Just use the subscript operator to set those entries.

solved Vector Subscript Out of Range C++ [closed]