470,874 Members | 1,596 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,874 developers. It's quick & easy.

Common Iterator for the same container

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[i] << y[i] << z[i] << endl; Bu

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

Thx.

Mar 1 '06 #1
2 1560
utab wrote:
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[i] << y[i] << z[i] << 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
--
I'm not just a number. To many, I'm known as a string...
Mar 1 '06 #2
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.

Mar 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

38 posts views Thread by Grant Edwards | last post: by
4 posts views Thread by Scott Smedley | last post: by
11 posts views Thread by Vivi Orunitia | last post: by
26 posts views Thread by Michael Klatt | last post: by
3 posts views Thread by utab | last post: by
18 posts views Thread by silversurfer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.