React.js
Angular
Ethical Hacking
Agile
AWS
BlockChain
Cassandra
Cloud
Salesforce
Scaled Agile
TOGAF
DevOps
GIT
Jenkins
Jira
Kibana
Linux
NGINX
Ansible
Artificial Intelligence
in C++ by

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

Click here to read more about DevOps

1 Answer

0 votes
by

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.

Related questions

Madanswer
+1 vote
+1 vote
asked Jul 16, 2019 in C++ by Indian
+1 vote
asked Jul 16, 2019 in C++ by Indian
+1 vote
asked Jul 16, 2019 in C++ by Indian
+1 vote
asked Jul 16, 2019 in C++ by Indian
...