deque - STL C++

deque<X, A>::insert()

Declaration

iterator deque<X,A>::insert(const_iterator qPos, const X& kxrValue) const;

Description

This is the insert() function for the deque class template.

Header Include

#include <deque>

Overloads

iterator deque<X,A>::insert(const_iterator qPos,
                             X&& xrrValue);

void deque<X,A>::insert(const_iterator qPos,
                         size_type qCount,
                         const X& kxrValue);

void deque<X,A>::insert(const_iterator qPos,
                         InputIterator qStart,
                         InputIterator qEnd);

Example

#include <iostream>
#include <deque>
#include <string>

int main()
{
	using namespace std;

	string qXoaX("XoaX.net");
	string qCpp("C++");
	string qVideo("Video");
	string qTurorials("Tutorials");

	// Create a deque instance
	deque<string> qD;
	qD.push_back(qXoaX);
	qD.push_back(qVideo);
	qD.push_back(qTurorials);

	// Output the deque
	deque<string>::iterator qIter;
	for (qIter = qD.begin(); qIter != qD.end(); ++qIter) {
		cout << *qIter << " ";
	}
	cout << endl;

	// Insert and output the deque
	qIter = qD.begin();
	++qIter;
	qD.insert(qIter, qCpp);
	for (qIter = qD.begin(); qIter != qD.end(); ++qIter) {
		cout << *qIter << " ";
	}
	cout << endl;

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

Output

deque<X, A>::insert() Output
 

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