473,472 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

vector::pointer confusion

I'm hoping someone can help me understand the vector::pointer..

What is the correct way to go about going from:

std::vector<char> myCharVector(30);

to a char* ? (bad example, but char *myCharArray = _______ .... )

Thanks!

--
Kristofer Pettijohn
kr*******@cybernetik.net
Jul 22 '05 #1
2 1218

"Kristofer Pettijohn" <kr*******@cybernetik.net> schrieb im
Newsbeitrag
news:41***********************@newsreader.cybernet ik.net...
I'm hoping someone can help me understand the vector::pointer..

What is the correct way to go about going from:

std::vector<char> myCharVector(30);

to a char* ?

char* Mychars = &myCharvector[0];
Jul 22 '05 #2

"Kristofer Pettijohn" <kr*******@cybernetik.net> wrote in message news:41***********************@newsreader.cybernet ik.net...
I'm hoping someone can help me understand the vector::pointer..

What is the correct way to go about going from:

std::vector<char> myCharVector(30);

to a char* ? (bad example, but char *myCharArray = _______ .... )


If myCharVector is going to stay around (and you're not going to add anything
to it that would cause a reallocation):

char* myCharArray = &myCharVector[0];

Otherwise, you're going to have to allocate a 30 element char array and copy
the contents into it.

Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cylin | last post by:
Dear all, Here is my code. ------------------------------ #include <iostream> #include <vector> using namespace std; class A { public:
6
by: Mattias Brändström | last post by:
Hello all! I am trying to write code that allows me to initialise one of my classes inline (with a vector like structure). Inline might not be the best term to use here but I can't think of any...
7
by: Andy Chang | last post by:
Hi, If I have typedef struct { std::vector <float> vSomeVal; int i; } VEC_T; Then is VEC_T * ptr a valid pointer to the struct accessing the vector? Also do I need to explicitly...
10
by: Bob | last post by:
Here's what I have: void miniVector<T>::insertOrder(miniVector<T>& v,const T& item) { int i, j; T target; vSize += 1; T newVector; newVector=new T;
3
by: Si | last post by:
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 ( doesn't seem to work)?
21
by: Peter Olcott | last post by:
I got the previous alias to std::vector working, and found that it takes up the space of a pointer. I want to find a way to do an alias to a std::vector that does not take up any space. Is there...
0
by: eomer | last post by:
Hello, I have a class called "Station" defined. If I want a vector that will store Station objects, is this the right syntax to create it: ...
1
by: Milan Krejci | last post by:
in myqtapp.h i have following declaration: typedef std::vector <LCDRange *vecLCD; vecLCD *vec; and in myqtapp.cpp i have following implementation: vec=new vecLCD; vec.push_back(lcdRange); but...
7
by: Kasya | last post by:
Hello, Whats the difference between std::vector<Object> obj; and std::vector<Object *> obj;. And which is recommended, preferred? Thanks, Kasya
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
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
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.