English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and example of vector front()

C++ Vector (Container)

It returns the first element of the vector (vector).

Syntax

Create a vector (vector), the syntax is:

v.front();

Parameter

This function does not contain any parameters.

Return value

This function returns the first element of the vector (vector).

Example1

Let's look at a simple example, using the front() method to return the first value of the vector.

#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string> language{"java","C","C"++"};"
cout << language.front();
return 0; 
}

Output:

java

In this example, the front() function displays the first element of the language object.

C++ Vector (Container)