无涯教程-C++ Deque - pop_front()函数

1 阅读1分钟

C++ Deque pop_front()函数从双端队列中删除第一个元素,并且集合的大小减小了一个。

pop_front - 语法

void pop_front(); 

pop_front - 参数

它不包含任何参数。

pop_front - 返回值

它不返回任何值。

pop_front - 例子1

让我们看一个简单的例子

#include <iostream>
#include<deque>
using namespace std;
int main()
{
    deque<int> d={10,20,30,40,50};
    deque<int>::iterator itr;
    d.pop_front();
    for(itr=d.begin();itr!=d.end();++itr)
    cout<<*itr<<" ";
    return 0;
  }

输出:

20 30 40 50 

在此示例中,pop_front()函数从双端队列中删除第一个元素,即10。

pop_front - 例子2

让我们看一个简单的例子

#include <iostream>
#include<deque>
using namespace std;
int main()
{
    deque<string> language={"C","C++","java",".net"};
    deque<string>::iterator itr;
    language.pop_front();
    for(itr=language.begin();itr!=language.end();++itr)
    cout<<*itr<<" ";
    return 0;
 }

输出:

C++ java .net 

在此示例中,pop_front()函数从双端队列中删除第一个字符串,即" C"。

参考链接

www.learnfk.com/c++/cpp-deq…