• Advertisement

Archived

This topic is now archived and is closed to further replies.

simple question

This topic is 5554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

anybody know offhand what the routine is for copying only part of an array in c++? my first thought was to traverse through it with a loop and define all of the elements manually, but im sure there's a much much better way say for example, i have this: int *LargeBoxOfApples; LargeBoxOfApples = (int*) new int[1000]; //and this: int *SmallBoxOfApples; SmallBoxOfApples = (int*) new int[100]; say i want to copy the first 100 elements of the LargeBox into the SmallBox... [edit: i know that in this example a loop would be sufficient, but for my actual purposes, i'll be dealing with many thousands of elements, not just 100] -eldee ;another space monkey; [ Forced Evolution Studios ]

::evolve:: Do NOT let Dr. Mario touch your genitals. He is not a real doctor! [edited by - eldee on December 3, 2002 5:47:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
there we go.. for some reason i had memcmp stuck in my head, which
of course is for comparing memory.

thanks again guys.

-eldee
;another space monkey;
[ Forced Evolution Studios ]


::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

Share this post


Link to post
Share on other sites
hrm, i just realized that i''ll need to be able to
specify a starting and ending point in the copy buffer...
is a loop my only option here?

-eldee
;another space monkey;
[ Forced Evolution Studios ]


::evolve::

Do NOT let Dr. Mario touch your genitals. He is not a real doctor!

Share this post


Link to post
Share on other sites

memcpy(smallBox, &largeBox[start], sizeof(int) * (end - start));


where end - start <= sizeof(smallBox)/sizeof(smallBox[0])

scott

edit : erm...well the sizeof won't work with new, of course, but you get the idea...


[edited by - LizardAl on December 4, 2002 1:25:13 PM]

Share this post


Link to post
Share on other sites

  • Advertisement