目录

vector::front

描述 (Description)

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

声明 (Declaration)

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

C++98

reference front();
const_reference front() const;

参数 (Parameters)

没有

返回值

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

异常 (Exceptions)

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

时间复杂

常数即O(1)

例子 (Example)

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

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

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

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