目录

forward_list::front

描述 (Description)

C ++函数std::forward_list::front()返回对forward_list的第一个元素的引用。

声明 (Declaration)

以下是std :: forward_list :: front()函数形式std :: forward_list头的声明。

C++11

reference front();
const_reference front() const;

参数 (Parameters)

没有

返回值

如果object是常量限定,则返回常量引用,否则返回非常量引用。

异常 (Exceptions)

该成员函数从不抛出异常。

时间复杂

常数即O(1)

例子 (Example)

以下示例显示了std :: forward_list :: front()函数的用法。

#include <iostream>
#include <forward_list>
using namespace std;
int main(void) {
   forward_list<int> fl = {1, 2, 3, 4, 5};
   cout << "First element of the list = " << fl.front() << endl;
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

First element of the list = 1
↑回到顶部↑
WIKI教程 @2018