# vector中如何遍历所有数据啊

woshi1514 2013-02-22 09:42:56

for (int i=0;i<(trimesh->vertices.size());i++)
{
glBegin(GL_POINTS);

point[0] = (trimesh->vertices[i][0]);
point[1] = (trimesh->vertices[i][1]);
point[2] = (trimesh->vertices[i][2]);
glVertex3f(point[0], point[1], point[2]);

vector<point> vertices;//vertices是TriMesh类中的vector成员

typedef Vec<3,float> point;

Vec(T x, T y, T z)
{ VEC_STATIC_CHECK(D == 3); v[0] = x; v[1] = y; v[2] = z; }

...全文
443 15 点赞 打赏 收藏 举报

15 条回复

huangxiaofei 2013-02-27
vector::iterator啊，这是stl的标准遍历方法吧
• 打赏
• 举报

mujiok2003 2013-02-23

That may be a design decision, for example, to have move semantec. He asks for a simple fix instead of a new solusion
• 打赏
• 举报

billzheng 2013-02-23

C/C++ code?1234if(trimesh && !trimester->empty()){ //your code goes here}
Why trimesh needs to be a pointer to vector at all????
• 打赏
• 举报

mujiok2003 2013-02-23
``````
if(trimesh && !trimester->empty())
{
}
``````
• 打赏
• 举报

woshi1514 2013-02-23

• 打赏
• 举报

tonforce 2013-02-22

• 打赏
• 举报

caoh110 2013-02-22
``````
int sz = trimesh->vertices.size(); //在for循环里面每次访问后都会去访问下这个值，将这个值保存下来，避免重复访问
for (int i=0;i<sz;i++)
{
glBegin(GL_POINTS);

point[0]  =  (trimesh->vertices[i][0]);
point[1]  =  (trimesh->vertices[i][1]);
point[2]  =  (trimesh->vertices[i][2]);
glVertex3f(point[0], point[1], point[2]);
``````
• 打赏
• 举报

FingerStyle 2013-02-22
trimesh 是不是野指针了
• 打赏
• 举报

starytx 2013-02-22

• 打赏
• 举报

sunriseWang 2013-02-22

• 打赏
• 举报

Kaile 2013-02-22
for(size_t i = 0; i < v.size(); ++i)
• 打赏
• 举报

• 打赏
• 举报

• 打赏
• 举报

billzheng 2013-02-22

Can you post your code properly? It should be a hard issue!
• 打赏
• 举报

woshi1514 2013-02-22

• 打赏
• 举报

6.0w+

C++ 语言相关问题讨论，技术干货分享，前沿动态等

2013-02-22 09:42