我是 C++ 新手。我想在“向量”中打印一些值。
vector<GLubyte> m_coneIndices;
m_coneIndices.resize(m_bodyIndexCount + m_diskIndexCount);
vector<GLubyte>::iterator index = m_coneIndices.begin();
// Body triangles
for (int i = 0; i < coneSlices * 2; i += 2) {
*index++ = i;
*index++ = (i + 1) % (2 * coneSlices);
*index++ = (i + 3) % (2 * coneSlices);
}
// Disk triangles
for (int i = 1; i < coneSlices * 2 + 1; i += 2) {
*index++ = diskCenterIndex;
*index++ = i;
*index++ = (i + 2) % (2 * coneSlices);
}
这就是将值存储在“向量”中的方式。我试过了
cout << "indices"<< "\n";
for (int i=0; i<(coneSlices * 2 ); i+=2) {
cout << m_coneIndices[i] << ' ' << m_coneIndices[i+1] << ' ' << m_coneIndices[i+2] << ' ' << "\n";
}
并打印了一些垃圾值。让我知道这段代码有什么问题。