ineedhelpnow
- 649
- 0
i may have asked this before but what is the difference between and at(i)?
ex. courseGrades and courseGrades.at(i)
ex. courseGrades and courseGrades.at(i)
The discussion revolves around the differences between accessing elements in a vector using the subscript operator [i] and the member function at(i). Participants explore the implications of each method in terms of functionality and safety, particularly in the context of C++ programming.
Participants express differing views on the implications of using [i] versus at(i), particularly regarding safety and error handling. There is no consensus on a definitive preference or best practice.
Participants highlight that the distinction between the two methods may not be particularly relevant in practice, but the differences in error handling are noted as significant.
ineedhelpnow said:i may have asked this before but what is the difference between and at(i)?
ex. courseGrades and courseGrades.at(i)
ineedhelpnow said:so you can't call a function using courseGrades?
ineedhelpnow said:im confused. do you use to check through all the items in the list??
ineedhelpnow said:im confused. do you use to check through all the items in the list??
ineedhelpnow said:can someone please show me an example of that when to use and when to use at(i)?like a single line of code or something. it would make it a lot more clear...
#include <vector>
std::vector<int> v;
for (int i = 0; i < v.size(); ++i) {
cout << v[i] << ", ";
}
for (int i = 0; i < v.size(); ++i) {
cout << v.at(i) << ", ";
}