By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,401 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,401 IT Pros & Developers. It's quick & easy.

Access contents of pointer to std::vector

P: n/a
Si
How do I access the contents of an std:vector pointer (I mean access
contents of the vector)?

What is the correct notation for a pointer ( [index] doesn't seem to work)?
Nov 7 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Its just like another C++ object. There is nothing special about it. []
works fine as well. What problems are you specifically having with it?

---------
Ajay Kalra
aj*******@yahoo.com

Nov 7 '05 #2

P: n/a
Si wrote:
How do I access the contents of an std:vector pointer (I mean access
contents of the vector)?

What is the correct notation for a pointer ( [index] doesn't seem to work)?


Perhaps you need this

(*pointer)[index]

but it's hard to be sure because your description is vague. Post the code!

In any case ther is no special syntax for vectors or pointers to
vectors, the usual stuff works.

john
Nov 7 '05 #3

P: n/a
Hi

If I understand, you have something like

vector<int> *MyVec;

assuming the pointer is correctly allocated and there is data in...

to access an element you can use at() function. at() simply return the
element at the specified position but
with a range check. If you dont mind the overhead of a range check use it.

int elem = MyVec->at(0); // the first element
MyVec->at(0) = 5;

if you really want to use [] you can do

int elem = (*Myvec)[0];
(*Myvec)[0] = 5;

Eric
"Si" <si@hotmail.com> a écrit dans le message de news:
tq*****************@newsfe2-gui.ntli.net...
How do I access the contents of an std:vector pointer (I mean access
contents of the vector)?

What is the correct notation for a pointer ( [index] doesn't seem to
work)?

Nov 7 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.