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

vector::pointer confusion

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a

"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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.