Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > vector::pointer confusion

Reply
Thread Tools

vector::pointer confusion

 
 
Kristofer Pettijohn
Guest
Posts: n/a
 
      08-25-2004
I'm hoping someone can help me understand the vector:ointer..

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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Gernot Frisch
Guest
Posts: n/a
 
      08-25-2004

"Kristofer Pettijohn" <(E-Mail Removed)> schrieb im
Newsbeitrag
news:412c7200$0$37321$(E-Mail Removed) ik.net...
> I'm hoping someone can help me understand the vector:ointer..
>
> What is the correct way to go about going from:
>
> std::vector<char> myCharVector(30);
>
> to a char* ?



char* Mychars = &myCharvector[0];


 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      08-25-2004

"Kristofer Pettijohn" <(E-Mail Removed)> wrote in message news:412c7200$0$37321$(E-Mail Removed) ik.net...
> I'm hoping someone can help me understand the vector:ointer..
>
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mozilla & Firefox Confusion listsubscriber@hotmail.com Firefox 9 01-20-2005 05:09 PM
Confusion about location of Mozilla files (Mandrake Linux 10.0) Hallvard Tangeraas Firefox 0 09-14-2004 09:46 AM
Procedures in testbench confusion Peter Hermansson VHDL 2 08-25-2004 02:15 PM
confusion when resetting registers martin f. krafft VHDL 2 08-19-2004 06:29 AM
defined() confusion Chris Perl 2 12-18-2003 06:06 PM



Advertisments