Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between front() and begin()

Tags:

What is the difference between the front() and begin() functions that appears in many STL containers?

like image 754
Him_Jalpert Avatar asked Feb 15 '12 23:02

Him_Jalpert


People also ask

What is a begin () in C++?

vector::begin() and vector::end() in C++ STL vector::begin() function is a bidirectional iterator used to return an iterator pointing to the first element of the container.

What is the type of V begin ()?

vector::begin() begin() function is used to return an iterator pointing to the first element of the vector container. begin() function returns a bidirectional iterator to the first element of the container.

What is front in vector?

std::vector::frontReturns a reference to the first element in the vector. Unlike member vector::begin, which returns an iterator to this same element, this function returns a direct reference.

How do you call the first element of a vector in C++?

vector::front() This function can be used to fetch the first element of a vector container.


1 Answers

begin() returns an iterator that can be used to iterate through the collection, while front() just returns a reference to the first element of the collection.

like image 54
Joachim Isaksson Avatar answered Dec 31 '22 20:12

Joachim Isaksson