473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Access contents of pointer to std::vector

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
3 14722
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pelle Beckman | last post by:
Hi all, I have a few - beginners - questions: * Why can't I put object references in a std::vector, i.e std::vector<MyClass&> ? At least in doesnt work in gcc (mingw, win32) * What's the...
8
by: Simon Elliott | last post by:
#include <vector> #include <iostream> int main (int argc, char *argv) { std::vector<int> vi; vi.push_back(1); vi.push_back(2); vi.push_back(3); int* pi = vi.begin(); std::cout << "result:"...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
6
by: slyi | last post by:
Is it ok to assume that the following assertion is valid for all implementations of std::vector?: std::vector<T> v(10); T* p = &v; for (size_t n=0; n < v.size(); n++) assert( p+n == &v ); ...
32
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: ...
9
by: aaragon | last post by:
I am trying to create a vector of type T and everything goes fine until I try to iterate over it. For some reason, the compiler gives me an error when I declare std::vector<T>::iterator iter;...
2
by: zl2k | last post by:
hi, all I need to use gsl_vector pointer with std::vector but not sure how to free the memory when I don't need it. Here is a piece of the code. =================== std::vector<gsl_vector *...
5
by: barcaroller | last post by:
Is there a way of getting a C-style pointer to the contents of a vector<T> (similar to string's c_str)? If not, what is the most efficent way of doing this? The reason I need a C-style pointer...
13
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.