[Solved] The number of items printed from my vector is inconsistent with the supposed number of items IN the vector [closed]


When you execute these lines:

vector<string> wordSets(24);
wordSets.push_back("CHICKEN");

wordSets has 24 empty items an the item "CHICKEN". I suspect, you didn’t mean that. Changing the first line to:

vector<string> wordSets;

should fix the wrong number of items problem.

If you want to reduce the number of times memory is allocated by calls to push_back, you can use:

vector<string> wordSets;
wordSets.reserve(24);

This will make sure that wordSets has sufficient memory to hold upto 24 objects.

0

solved The number of items printed from my vector is inconsistent with the supposed number of items IN the vector [closed]