English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and example of Deque clear() function

C++ Deque (Double-ended Queue)

C ++ The Deque clear() function removes all elements from the deque and reduces the size of the deque to zero.

Syntax

void clear();

Parameters

It does not contain any parameters.

Return value

It does not return any value.

Example

Let's look at a simple example

#include iostream>
#include<deque>
using namespace std;
int main()
{
    deque<int> first;
    deque<int>::iterator itr;
    cout << "The content of the first deque is: ";
    first.push_back(1);
    first.push_back(2);
    first.push_back(3);
    for(itr=first.begin();itr!=first.end();++itr)
    cout <<*itr << " \" ";
    cout << '\n';
    first.clear();
    cout << "Now, the content of the first deque is: ";
    first.push_back(4);
    first.push_back(5);
    first.push_back(6);
    for(itr=first.begin();itr!=first.end();++itr)
    cout <<*itr << " \" ";
    return 0;
}

Output:

The content of the first deque is:1 2 3 
Now, the content of the first deque is:4 5 6

C++ Deque (Double-ended Queue)