随机坐标中的 cout 向量 n 次
Cout Vector in Random Coordinates n times
我正在尝试在随机坐标处循环 12 次向量。我在这里创建了我的矢量:
vector<Item> sV(MAXPILLS, pill);
目前它只打印出其中一个矢量。这是我的代码,用于矢量的随机坐标以及尝试打印出其中的 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 次。除非里面有一些隐藏的功能,如果是这样,我感到羞耻。
相关文章:
- 写入向量<向量<bool>>
- 函数向量_指针有不同的原型,我可以构建一个吗
- std::向量与传递值的动态数组
- 将值指定给向量(2D)的向量中的某个位置
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 如何使用向量的template_back函数
- 尝试通过多个向量访问变量时,向量下标超出范围
- 如何通过派生类函数更改基类中的向量
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- C++从另一个类访问公共静态向量的正确方法是什么
- 如何将ampl中的集合表示为c++中的向量
- 如何在C++中编写 ostream 的向量,它接收所有不同的输出流,如 cout、ostringstream 和 ofs
- C++ 不能在cout中使用向量和字符串文字
- C++中带有 cout 运算符问题的向量
- 随机坐标中的 cout 向量 n 次
- 将多个整数添加到一个向量索引? 'Cout'不起作用
- 在递归函数中收集cout或输出为向量
- cout 字符串和向量在同一行中
- 为什么这段代码在试图将.txt放入向量并对其进行cout时会返回空白控制台
- 如何访问(例如,cout)多维STL向量中的迭代器的当前值(c++)