vector::pointer confusion

Discussion in 'C++' started by Kristofer Pettijohn, Aug 25, 2004.

  1. 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
    Kristofer Pettijohn, Aug 25, 2004
    #1
    1. Advertising

  2. "Kristofer Pettijohn" <> schrieb im
    Newsbeitrag
    news:412c7200$0$37321$...
    > 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];
    Gernot Frisch, Aug 25, 2004
    #2
    1. Advertising

  3. Kristofer Pettijohn

    Ron Natalie Guest

    "Kristofer Pettijohn" <> wrote in message news:412c7200$0$37321$...
    > 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.
    Ron Natalie, Aug 25, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pmatos
    Replies:
    6
    Views:
    23,767
  2. Replies:
    8
    Views:
    1,910
    Csaba
    Feb 18, 2006
  3. Kavya
    Replies:
    2
    Views:
    378
  4. Javier
    Replies:
    2
    Views:
    556
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    354
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page