Jul 16, 2019 in C Plus Plus
Q:

 How to get element by index in vector | at() vs operator []

1 Answer

0 votes
Jul 16, 2019

std::vector provides [] operator i.e.

1

element_reference operator[] (size_type n);

It returns the reference of element in vector at index n.

std::vector provides an another member function at() i.e.

reference at(size_type n);

It returns the reference of element at index n in vector. If index n is out of range i.e. greater then size of vector then it will throw out_of_range exception.

Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

+1 vote
+1 vote
Jul 16, 2019 in C Plus Plus
...