How to access elements of a range in a vector??

Discussion in 'C++' started by Sachin, Sep 6, 2010.

  1. Sachin

    Sachin Guest

    Hi,
    I want to do a task of modifying the elements in a range, say 5th
    element to 10th element.. I also know that there is a function
    TRANSFORM which is used to transform the elements of any container,
    say a vector, but in that function, the arguments are iterators, and
    what I have is a range and not iterators to these elements.

    Eg
    vector<int> v;
    v.transform(v.begin(),v.end(),v.begin(),modifying_func);
    //this, I want to apply not from begin to end, but from say, element
    at index i to index j;
    //similarly, if I want to know the values in a range of vector or
    list, not from begin to end, how can I //get to know that??

    So is there any function or way in which I can do this operation??
    Sachin, Sep 6, 2010
    #1
    1. Advertising

  2. Sachin

    tni Guest

    On 2010-09-06 11:11, Sachin wrote:
    > Hi,
    > I want to do a task of modifying the elements in a range, say 5th
    > element to 10th element.. I also know that there is a function
    > TRANSFORM which is used to transform the elements of any container,
    > say a vector, but in that function, the arguments are iterators, and
    > what I have is a range and not iterators to these elements.
    >
    > Eg
    > vector<int> v;
    > v.transform(v.begin(),v.end(),v.begin(),modifying_func);
    > //this, I want to apply not from begin to end, but from say, element
    > at index i to index j;
    > //similarly, if I want to know the values in a range of vector or
    > list, not from begin to end, how can I //get to know that??
    >
    > So is there any function or way in which I can do this operation??


    An iterator to the 5th element would be:
    v.begin() + 5
    tni, Sep 6, 2010
    #2
    1. Advertising

  3. Sachin

    James Kanze Guest

    On Sep 6, 10:18 am, tni <> wrote:
    > On 2010-09-06 11:11, Sachin wrote:


    [...]
    > An iterator to the 5th element would be:
    > v.begin() + 5


    That's an iterator to the 6th element.

    --
    James Kanze
    James Kanze, Sep 6, 2010
    #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. pmatos
    Replies:
    6
    Views:
    23,705
  2. Replies:
    46
    Views:
    936
    Antoon Pardon
    Jul 25, 2006
  3. Replies:
    8
    Views:
    1,877
    Csaba
    Feb 18, 2006
  4. Javier
    Replies:
    2
    Views:
    533
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    338
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page