Use std::copy to print out all elements in a deque
#include <iostream>
using std::cout;
using std::endl;
#include <deque> // deque class-template definition
#include <algorithm> // copy algorithm
#include <iterator> // ostream_iterator
int main()
{
std::deque< double > values; // create deque of doubles
std::ostream_iterator< double > output( cout, " " );
// insert elements in values
values.push_front( 2.2 );
values.push_front( 3.5 );
values.push_back( 1.1 );
cout << "values contains: ";
std::copy( values.begin(), values.end(), output );
values.pop_front(); // remove first element
cout << "\nAfter pop_front, values contains: ";
std::copy( values.begin(), values.end(), output );
cout << endl;
return 0;
}
/*
values contains: 3.5 2.2 1.1
After pop_front, values contains: 2.2 1.1
*/
Related examples in the same category