关于色彩搭配的网站,微商货源网站源码,网站个人备案,公司想建个网站c stlGiven a list with some of the elements, we have to access its first and last elements of the list in C (STL) program. 给定包含某些元素的列表#xff0c;我们必须在C (STL)程序中访问列表的第一个和最后一个元素。 列表的front()和back()函数 (front() and ba…c stlGiven a list with some of the elements, we have to access its first and last elements of the list in C (STL) program. 给定包含某些元素的列表我们必须在C (STL)程序中访问列表的第一个和最后一个元素。 列表的front()和back()函数 (front() and back() function of the list) These are two functions which can be used to get the first and last element of the list. front() returns the first element and back() returns the last element. 这是两个函数可用于获取列表的第一个和最后一个元素。 front()返回第一个元素 back()返回最后一个元素。 Lets implement the program below... 让我们实现下面的程序... Example: 例 Input:
List: [10, 20, 30, 40, 50]
Output:
First element: 10
Last element: 50
Program: 程序 #include iostream
#include list
using namespace std;
int main()
{
listint iList {10, 20, 30, 40, 50};
coutFirst element: iList.front()endl;
coutLast element: iList.back()endl;
return 0;
}
Output 输出量 First element: 10
Last element: 50
翻译自: https://www.includehelp.com/stl/get-the-first-and-last-element-of-the-list.aspxc stl