I thought I read something about shifting all of the elements of an array to the left or right but I can't find anything on google. Is this possible or am I wrong. I'm making a blackjack game and this might come in handy. Thanks
I am not familiar with this myself. However, if this doesn't exist, you maybe thinking of the shift-left and shift-right operators. These operate on bits though, not arrays.
Someone else might chime in with an Array function, but I am personally not familiar with one.
I leave it as an exercise for you to stick this stuff in usefull functions.
Oh yeah, lest I forget:
If your array is of objects (and not unmanaged types: simple types and structs and the like) you must make sure to zero the element(s) on the end that were moved out. Otherwise you may find yourself with some serious memory corruption! (Objects are meant to be duplicated with their copy constructors, not by simply copying their bits as memmove() does.)
Ahhh I knew someone else would have a way to do it :) Can't say I have ever used it, nor would I :P Looks like an easy way to develop a serious case of Memory Leak.
Agreed. Any of the standard containers (vector, deque, list) allow very easy push/pop from the ends, which is essentially the same thing...
[edit]
But I would like to reiterate that using memmove() really isn't troublesome: for things like int/float/struct arrays using it is the same as doing it "manually", just much faster.