std::vector continuity

Discussion in 'C++' started by Lynn, Dec 13, 2004.

  1. Lynn

    Lynn Guest

    Are std::vector items guaranteed to be continuous ?

    For instance, if I have a "std::vector <char> text".
    If I get a pointer "char *p = & text [0];", can use the
    pointer to work thru the limits of the vector ?

    Thanks,
    Lynn McGuire
     
    Lynn, Dec 13, 2004
    #1
    1. Advertising

  2. Lynn

    Ron Natalie Guest

    Lynn wrote:
    > Are std::vector items guaranteed to be continuous ?
    >
    > For instance, if I have a "std::vector <char> text".
    > If I get a pointer "char *p = & text [0];", can use the
    > pointer to work thru the limits of the vector ?

    Yes, until you cause the capacity of the vector to change.
     
    Ron Natalie, Dec 13, 2004
    #2
    1. Advertising

  3. Lynn

    Rolf Magnus Guest

    Lynn wrote:

    > Are std::vector items guaranteed to be continuous ?


    Yes. Well, they officially weren't before the 2003 version of the C++
    standard, but there seems to be no known implementation that didn't store
    the data continuously.

    > For instance, if I have a "std::vector <char> text".
    > If I get a pointer "char *p = & text [0];", can use the
    > pointer to work thru the limits of the vector ?


    Yes.
     
    Rolf Magnus, Dec 14, 2004
    #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. Anonymous
    Replies:
    20
    Views:
    4,436
    Pete Becker
    Mar 30, 2005
  2. Jason Heyes
    Replies:
    8
    Views:
    769
    Andrew Koenig
    Jan 15, 2006
  3. Replies:
    8
    Views:
    2,005
    Csaba
    Feb 18, 2006
  4. milesd
    Replies:
    0
    Views:
    271
    milesd
    Mar 4, 2008
  5. Rune Allnor
    Replies:
    4
    Views:
    994
    Rune Allnor
    Dec 11, 2008
Loading...

Share This Page