Common Iterator for the same container

U

utab

Hi, there

Assume that I have three vectors x,y and z that has the same number of
elements. Can I use a common iterator for these three.

I did it with iterx, itery and iterz but the thing I wondered was: in a
for loop you can write array elements by using the same index such as;

for (int i = 0 ; i!=10; ++i )
cout << x << y << z << endl; Bu

So I just wondered if sth is possible with iterators(common ?) in
order to get the container elements

Thx.
 
B

Ben Pope

utab said:
Hi, there

Assume that I have three vectors x,y and z that has the same number of
elements. Can I use a common iterator for these three.

I did it with iterx, itery and iterz but the thing I wondered was: in a
for loop you can write array elements by using the same index such as;

for (int i = 0 ; i!=10; ++i )
cout << x << y << z << endl; Bu

So I just wondered if sth is possible with iterators(common ?) in
order to get the container elements


Iterators allow you to traverse a sequence. The elements of different
vectors are not a sequence.

If x, y and z are closely related, do:
struct stuff {
X x;
Y y;
Z z;
}

std::vector<stuff> vec;
iter->x;



Ben Pope
 
U

utab

Thx,

this is a nice idea if you can not do directly, put them into a form
that they can be handled in the way you want.

I will keep this advice.
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top