我试图在随机坐标处循环计算一个 vector 12 次。我在这里创建了我的 vector :
vector<Item> sV(MAXPILLS, pill);
目前它只打印出一个 vector 。这是我的 vector 随机坐标代码,并尝试打印其中的 12 个坐标。如果您能提供帮助,我将不胜感激!
void generatePowerPills(char gr[][SIZEX], Item pill){
for (int i = 0; i < 12; i++)
{
gr[pill.y][pill.x] = pill.symbol;
}
}
void initialiseRandomPillsCoordinates(vector<Item>& sV) {
//pass the vector to the function to give each pill random coordinates
Seed();
for (size_t i(0); i < sV.size(); ++i)
{
sV.at(i).y = Random(SIZEY - 2); //vertical coordinate in range [1..(SIZEY - 2)]
sV.at(i).x = Random(SIZEX - 2); //horizontal coordinate in range [1..(SIZEX - 2)]
}
}
最佳答案
我只是评论,但遗憾的是我只能回答。不管怎样,你在这里迭代:
for (int i = 0; i < 12; i++)
{
gr[pill.y][pill.x] = pill.symbol;
}
但是你在这个循环中的什么地方使用了“i”?看起来它会做同样的事情,12 次。除非里面某处有一些隐藏的功能,如果是这样,我真可耻。
关于c++ - cout 随机坐标 vector n 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29798677/