C++ memcpy

Discussion in 'C++' started by barcaroller, Apr 12, 2007.

  1. barcaroller

    barcaroller Guest

    Does C++ have an equivalent for C's memcpy? I have two memory blocks
    (created using new, not malloc) and I need to copy the contents of one to
    the other. The memory blocks are just that; they are not objects.
    barcaroller, Apr 12, 2007
    #1
    1. Advertising

  2. barcaroller

    red floyd Guest

    barcaroller wrote:
    > Does C++ have an equivalent for C's memcpy? I have two memory blocks
    > (created using new, not malloc) and I need to copy the contents of one to
    > the other. The memory blocks are just that; they are not objects.


    Yes, memcpy. The C Standard Library is part of the C++ Standard Library.
    red floyd, Apr 12, 2007
    #2
    1. Advertising

  3. barcaroller

    Greg Comeau Guest

    In article <evm7ja$7fo$>, barcaroller <> wrote:
    >Does C++ have an equivalent for C's memcpy? I have two memory blocks
    >(created using new, not malloc) and I need to copy the contents of one to
    >the other. The memory blocks are just that; they are not objects.


    memcpy is part of the C++ Standard Library as well.
    If can be accessed via <string.h> or <cstring> and
    may or may not need std:: qualification (the standard
    is clear on when it's required, but compilers are
    across the board on applying it still).
    --
    Greg Comeau / 4.3.9 with C++0xisms now in beta!
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
    Greg Comeau, Apr 12, 2007
    #3
  4. barcaroller wrote:
    > Does C++ have an equivalent for C's memcpy? I have two memory blocks
    > (created using new, not malloc) and I need to copy the contents of one to
    > the other. The memory blocks are just that; they are not objects.


    C++ has memcpy.

    #include <cstring>

    int main()
    {
    char a[10], b[10];

    std::memcpy(a, b, sizeof(a));
    }

    You can also use std::copy. On some compilers, a std::copy of POD's
    will turn into a memcpy.
    Gianni Mariani, Apr 12, 2007
    #4
    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. John Edwards
    Replies:
    1
    Views:
    569
    Dave Rahardja
    Aug 7, 2003
  2. David Bradley
    Replies:
    0
    Views:
    529
    David Bradley
    Aug 7, 2003
  3. Ninan Thomas
    Replies:
    3
    Views:
    408
    Kevin Goodsell
    Aug 22, 2003
  4. Bren
    Replies:
    8
    Views:
    2,011
    Stephen Howe
    Sep 4, 2003
  5. Replies:
    13
    Views:
    17,759
    White Wolf
    Sep 18, 2003
Loading...

Share This Page