algorithm - STL C++

move_backward()

Declaration

template <class BidirectionalIterator1, BidirectionalIterator2>
BidirectionalIterator2 move_backward(
	BidirectionalIterator1 xFirst,
	BidirectionalIterator1 xLast,
	BidirectionalIterator2 xDest
);

Description

This function moves the entries in the range from "xFirst" up through the one before "xLast" to the range ending the entry one before "xDest."

Header Include

#include <algorithm>

Example

#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	using namespace std;

	// Create a vector instance
	vector<char> qV;
	qV.push_back('X');
	qV.push_back('o');
	qV.push_back('a');
	qV.push_back('X');
	qV.push_back('.');
	qV.push_back('n');
	qV.push_back('e');
	qV.push_back('t');

	vector<char>::iterator qIter;
	// Output the vector
	cout << "The Vector: ";
	for (qIter = qV.begin(); qIter != qV.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	// Move the first four entries to the end of a new vector
	vector<char> qMove(10, '*');
	qIter = move_backward(qV.begin(), qV.begin() + 4, qMove.end());

	cout << "Moved Vector: ";
	for (qIter = qMove.begin(); qIter != qMove.end(); ++qIter) {
		cout << *qIter;
	}
	cout << endl;

	// Keep the window open
	cin.get();
	return 0;
}

Output

move_backward() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.