×

C++ STL Tutorial

C++ STL Algorithm

C++ STL Arrays

C++ STL String

C++ STL List

C++ STL Stack

C++ STL Set

C++ STL Queue

C++ STL Vector

C++ STL Map

C++ STL Multimap

C++ STL MISC.

Push and print elements in an integer deque in C++ STL

C++ STL deque: Here, we are implementing a program in which we are declaring an integer deque, pushing the elements and printing the elements.
Submitted by IncludeHelp, on June 18, 2019

Push and print elements in an integer deque

In this example, we are declaring an integer deque and pushing the elements using a for loop with the counter starting value from 1 to 5 and then printing the value separated by space.

C++ program to push and print elements in an integer deque

#include <iostream>
#include <deque> //for deque
using namespace std;

int main()
{
    // deque  for integer elements
    deque<int> d1;

    // adding 5 elements
    for (int i = 1; i <= 5; ++i) {
        d1.push_back(i);
    }

    // print all elements
    cout << "deque elements are: ";
    for (int i = 0; i < d1.size(); ++i) {
        cout << d1[i] << ' ';
    }
    cout << endl;

    return 0;
}

Output

deque elements are: 1 2 3 4 5

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.