• Advertisement
Sign in to follow this  

C++ Vector Structure

This topic is 3614 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

Hello, I was just wondering if anyone could take the time to explain to me what C++ Vector strucutres are? If anyone could also tell me how i could use them to store information like vertices. And could i use a vector structure within a vector structure. Cheers ~Qwertyuiop23

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by qwertyuiop23
Hello,

I was just wondering if anyone could take the time to explain to me what C++ Vector strucutres are? If anyone could also tell me how i could use them to store information like vertices. And could i use a vector structure within a vector structure.

Cheers
~Qwertyuiop23
Do you mean std::vector?

If you search the forum archives for 'vector', you'll probably turn up some examples of use. There are also some good references online; I usually start here when I need info about the containers and algorithms portion of the standard library (insert standard disclaimer about the differences between SGI's STL and the corresponding portions of the SC++L here...).

Here's a quick sample to get you started:
// Declare a dynamic array of integers:
std::vector<int> v;

// Add a few elements:
v.push_back(1);
v.push_back(2);
v.push_back(3);

// Add some more:
for (int i = 4; i <= 10; ++i) {
v.push_back(i);
}

// Grab a pointer for use with (e.g.) OpenGL (be sure not to keep this around!):
int* p = &v.front();

// Is the array empty?
if (v.empty()) {
std::cout << "The array is empty!" << std::endl;
} else {
std::cout << "The array is not empty!" << std::endl;
}

// Empty the array:
v.clear();

// Create an array of arrays:
std::vector< std::vector<int> > vv;

// Add an element:
vv.push_back(std::vector<int>());

// Add an element to that element:
vv.front().push_back(1);
Not compiled or tested (there's a lot more to learn, so be sure to consult a good reference on the subject).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement