YetiCodeCamp - C++ for Beginners

Companion website for the C++ for Beginners YouTube video series.

C++ Vector front() Function

The C++ vector.front() function returns a reference to the first element of a vector. This function does not take any parameters.


Example, using a vector “v1”.


Returns the value in the first element of the vector.

This example is a complete program using the vector front() function to return the value of the first element in a vector.


int main()
std::vector<std::string> month{"Jan","Feb","Mar","Apr","May","Jun",
return 0;

Output: Jan