Iterator values may change.
#include <iostream>
#include <deque>
using namespace std;
int main()
{
deque<char> dequeObject;
deque<char>::iterator p1, p2;
int i;
for(i = 0; i <5; i++)
dequeObject.push_back(i + 'A');
cout << "Original sequence: ";
for(i = 0; i <dequeObject.size(); i++)
cout << dequeObject[i] << " ";
cout << endl;
p1 = dequeObject.begin() + 2;
p2 = dequeObject.begin() + 3;
cout << "*p1: " << *p1 << ", ";
cout << "*p2: " << *p2 << endl;
cout << endl;
dequeObject.insert(p1, 'X');
cout << "Sequence after insert: ";
for(i = 0; i <dequeObject.size(); i++)
cout << dequeObject[i] << " ";
cout << endl;
cout << "*p1: " << *p1 << ", ";
cout << "*p2: " << *p2 << endl;
return 0;
}
Related examples in the same category