报错can't dereference out of range iterator
void player::setblock()
{
int flag = 1;
block.push_back({ 0,0 });
srand(static_cast<unsigned int>(time(NULL)));
while (flag)
{
block.end()->x = rand() * (20) + 10;
block.end()->y = rand() * (20) + 10;//随机得到坐标
for (vector<mountain>::iterator iter = block.begin(); iter != block.end(); ++iter)//迭代器(有问题)
{
if (iter->x == block.end()->x && iter->y == block.end()->y)//如果重复
continue;
}
if (block.end()->x < 800 && block.end()->y)//防止超出棋盘
{
cout << "得到正确坐标";
flag--;
drawmountain(block.end()->x, block.end()->y);
block.push_back({ 0,0 });
}
}
}
报错can't dereference out of range iterator
我想要能检测产生的随机坐标是否重复且不超出最大范围