std::vector continuity

L

Lynn

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
 
R

Ron Natalie

Lynn said:
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.
 
R

Rolf Magnus

Lynn said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top