Access a list of vectors

S

steflhermitte

Dear cpp-ians,

I have created a list of vectors and its iterator:

list < vector <long double> > listValues;
list < vector <long double> >::iterator itListValues;

but I don't know how to access the elements of that list.
I have a list of vectors with 4 elements. The size of my list is 500,
the size of every vector is 4.

How do I move around in that list of vectors?
E.g:
When I want to access the elements in my list that are the fourth
element in my vector?
for (itListValues = listValues.begin()[4];
itListValues < listValues.end()[4]; itListValues++)
{ *itListValues; }

This is not correct, but I don't know how to write it differently to
access the individual values of my list of vectors. Any advice?

Thank you in advance,
Stef
 
V

Victor Bazarov

steflhermitte said:
I have created a list of vectors and its iterator:

list < vector <long double> > listValues;
list < vector <long double> >::iterator itListValues;

but I don't know how to access the elements of that list.
I have a list of vectors with 4 elements. The size of my list is 500,
the size of every vector is 4.

How do I move around in that list of vectors?
E.g:
When I want to access the elements in my list that are the fourth
element in my vector?
for (itListValues = listValues.begin()[4];
itListValues < listValues.end()[4]; itListValues++)
{ *itListValues; }

This is not correct, but I don't know how to write it differently to
access the individual values of my list of vectors. Any advice?


for (itListValues = listValues.begin();
itListValues != listValues.end(); ++itListValues)
{
vector<long double>& v = *itListValues;
long double sum = v[0] + v[1] + v[2] + v[3];
}

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top