📜  在C++ STL中列出pop_front()函数

📅  最后修改于: 2021-05-30 12:31:17             🧑  作者: Mango

list :: pop_front()是C++ STL中的内置函数,用于从列表容器的开头删除元素。因此,此函数将容器的大小减小1,因为它从列表的开头删除了元素。

语法

list_name.pop_front();

参数:该函数不接受任何参数。

返回值:该函数不返回任何内容。

下面的程序说明了C++ STL中的list :: pop_front()函数:

// CPP program to illustrate the
// list::pop_front() function
#include 
using namespace std;
  
int main()
{
    // Creating a list
    list demoList;
  
    // Adding elements to the list
    // using push_back()
    demoList.push_back(10);
    demoList.push_back(20);
    demoList.push_back(30);
    demoList.push_back(40);
  
    // Initial List:
    cout << "Initial List: ";
    for (auto itr = demoList.begin(); itr != demoList.end(); itr++)
        cout << *itr << " ";
  
    // removing an element from the front of List
    // using pop_front
    demoList.pop_front();
  
    // List after removing element from front
    cout << "\n\nList after removing an element from front: ";
    for (auto itr = demoList.begin(); itr != demoList.end(); itr++)
        cout << *itr << " ";
  
    return 0;
}
输出:
Initial List: 10 20 30 40 

List after removing an element from front: 20 30 40
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”