Common Iterator for the same container

Discussion in 'C++' started by utab, Mar 1, 2006.

  1. utab

    utab Guest

    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.
    utab, Mar 1, 2006
    #1
    1. Advertising

  2. utab

    Ben Pope Guest

    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 << 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
    --
    I'm not just a number. To many, I'm known as a string...
    Ben Pope, Mar 1, 2006
    #2
    1. Advertising

  3. utab

    utab Guest

    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.
    utab, Mar 1, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vivi Orunitia
    Replies:
    11
    Views:
    4,454
    Martijn Lievaart
    Feb 4, 2004
  2. utab
    Replies:
    3
    Views:
    253
    benben
    Mar 2, 2006
  3. Denny
    Replies:
    1
    Views:
    767
  4. John Reye
    Replies:
    28
    Views:
    1,345
    Tim Rentsch
    May 8, 2012
  5. Jason Mellone
    Replies:
    3
    Views:
    82
    Jurko Gospodnetić
    May 7, 2014
Loading...

Share This Page