Common Iterator for the same container

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • utab

    #1

    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(commo n ?) in
    order to get the container elements

    Thx.

  • Ben Pope

    #2
    Re: Common Iterator for the same container

    utab wrote:[color=blue]
    > 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(commo n ?) in
    > order to get the container elements[/color]

    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<stu ff> vec;
    iter->x;



    Ben Pope
    --
    I'm not just a number. To many, I'm known as a string...

    Comment

    • utab

      #3
      Re: Common Iterator for the same container

      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.

      Comment

      Working...