Why does this happen my program says that it has no errors but then when I run it I get terminate called after throwing an instance of \'std::out_of_range\' what(): vector:_M_ra
You access elements in deck
here:
num1 = deck.at(pos1);
num2 = deck.at(pos2);
but it is empty. You have to fill it at some point before making those calls. You can check if a vector is empty with the std::vector::empty
method, and get it's size with std::vector::size
. See this std::vector reference for more information on those two methods.