Connecting Tech Pros Worldwide Help | Site Map

Access contents of pointer to std::vector

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 7th, 2005, 07:15 PM
Si
Guest
 
Posts: n/a
Default Access contents of pointer to std::vector

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, 07:25 PM
Ajay Kalra
Guest
 
Posts: n/a
Default 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, 07:35 PM
John Harrison
Guest
 
Posts: n/a
Default 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, 07:45 PM
Eric Pruneau
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.