C++ Deque 中的 pop_front()函数

首页 / C++入门教程 / C++ Deque 中的 pop_front()函数

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

pop_front - 语法

void pop_front(); 

pop_front - 参数

它不包含任何参数。

pop_front - 返回值

它不返回任何值。

无涯教程网

pop_front - 例子1

让我们看一个简单的例子

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-deque-pop-front-function.html

来源:LearnFk无涯教程网

#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

让我们看一个简单的例子

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-deque-pop-front-function.html

来源:LearnFk无涯教程网

#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"。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

趣谈Linux操作系统 -〔刘超〕

Web协议详解与抓包实战 -〔陶辉〕

DevOps实战笔记 -〔石雪峰〕

接口测试入门课 -〔陈磊〕

Service Mesh实战 -〔马若飞〕

微信小程序全栈开发实战 -〔李艺〕

数据分析思维课 -〔郭炜〕

PyTorch深度学习实战 -〔方远〕

高并发系统实战课 -〔徐长龙〕

好记忆不如烂笔头。留下您的足迹吧 :)