Connecting Tech Pros Worldwide Help | Site Map

Access contents of pointer to std::vector

  #1  
Old November 7th, 2005, 08:15 PM
Si
Guest
 
Posts: n/a
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)?


  #2  
Old November 7th, 2005, 08:25 PM
Ajay Kalra
Guest
 
Posts: n/a

re: Access contents of pointer to std::vector


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
ajaykalra@yahoo.com

  #3  
Old November 7th, 2005, 08:35 PM
John Harrison
Guest
 
Posts: n/a

re: Access contents of pointer to std::vector


Si wrote:[color=blue]
> 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)?
>
>[/color]

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
  #4  
Old November 7th, 2005, 08:45 PM
Eric Pruneau
Guest
 
Posts: n/a

re: Access contents of pointer to std::vector


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:
tqObf.7477$wh7.4152@newsfe2-gui.ntli.net...[color=blue]
> 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)?
>[/color]


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Valarray/Pointer to first Element Chris Forone answers 10 November 3rd, 2007 10:55 AM
Pointer to vector<T> contents barcaroller answers 5 May 8th, 2007 05:05 PM
create a dynamic array of pointers with initial values of NULL sandy@murdocks.on.ca answers 23 December 1st, 2006 11:05 PM
pointer iterator interaction silversurfer answers 18 July 3rd, 2006 11:35 AM