There is a function std::rotate() in <algorithm> (but you have to
set the last element yourself). Here is an example using
rotate with std::vector ... it also works with an array or CArray,
\but the call will be slightly different:
HI cilu.... I'm implementing a MFC DLL and I have vectors... i'm using VisualStudio 2008... so thanks to Philip Nicoletti for the std::rotate() hint...
There is no vector class in MFC, and no, there is no function to do that automatically. You need to do that manually.
If you use a list, you can remove the first element and and one at the tail.
If you use an array, you have to copy the elements, one by one, from i+1 to i, and then set the value you want for the last element.
There is a 'sort of' automatic way using MFC's CArray class. Store the first item, Delete the first item and add the former first to the end.
Assuming int as type (should work for any type really).
Code:
int i = array[ array.GetUpperBound() ];
array.RemoveAt(0);
array.Add(i);
HI cilu.... I'm implementing a MFC DLL and I have vectors... i'm using VisualStudio 2008... so thanks to Philip Nicoletti for the std::rotate() hint...
When you prefixed your title with [MFC] I made the assumption you talk about MFC containers, that don't feature a "vector". How could we figure that you mean std::vector when you didn't mention that at all? You should ask the questions correctly, without ambiguities.
Bookmarks