Archived

This topic is now archived and is closed to further replies.

Arrays and vectors.

This topic is 5626 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m very new to the standard template library and was wondering how to implement the following as a vector: int nVertices; fscanf(hFileHandle, "%i ", &nVertices); float fVertexArray[nVertices][3]; I know I can''t do this arrays as I have found out, and I know that a vector would do the job, but don''t know how to implement one let alone a 2D one. Any help would be gratefully received. Cheers, - CheeseMonger

Share this post


Link to post
Share on other sites
int nVertices;
fscanf(hFileHandle, "%i ", &nVertices);
float fVertexArray[nVertices][3];


bool resize_3(const std::vector<float> & v)
{
v.resize(3);
return true;
}
int main()
{
...
 
int nVertices;
fin >> nVertices; // fin is an ifstream object that has opened the specified file
vector< vector<float> > fVertexArray;
fVertexArray.resize(nVertices);
for_each(fVertexArray.begin(), fVertexArray.end(), resize_3);
 
...
return 0;
}


quote:
I know I can''t do this arrays...

You can do it as dynamic arrays. You can also create a vertex structure and use a vector/dynamic array of those.

As I like to say, if you''re using C++, use C++.

Share this post


Link to post
Share on other sites