Click to See Complete Forum and Search --> : vectors!


mihsah
February 5th, 2008, 04:12 PM
how do we access vector indexes for instance 0,1,2,3 without using addresses and references?

wildfrog
February 5th, 2008, 04:21 PM
Like this?

std::vector<int> vec;
vec.push_back(1);
vec.push_back(2);

int i = vec[1];

- petter

MikeAThon
February 5th, 2008, 06:36 PM
Or maybe using an iterator??
std::vector<int> vec;
vec.push_back(1);
vec.push_back(2);

std::vector<int>::iterator it = vec.begin();

int i = *it;
int j = *(it++);
Mike

Mybowlcut
February 5th, 2008, 11:25 PM
std::vector<int> vec;
vec.push_back(1);
vec.push_back(2);

int i = vec.at(0);
int j = vec.at(1);? :p