terminate called after throwing an instance of 'std::out_of_range'

前端 未结 2 879
不思量自难忘°
不思量自难忘° 2021-02-10 05:41

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

2条回答
  •  长情又很酷
    2021-02-10 06:02

    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.

提交回复
热议问题