Friday, August 20, 2010

Vector at() Function

If you have a vector v; v.at(10) will do range checking, while v[10] will not.

Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 152.

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Vector’s at function is used to get an element at particular index. It’s means that must be filled before to get. In literal meaning, at is representing as rvalue.
    While vector v[10] can be used as both means lvalue as well as rvalue.
    Vector v;
    For (int I = 0; I < 15; i++)
    {
    V[i] = i;
    }
    If v[i] will do range checking then you will be unable to assign data with subscript operator.
    Hence, there is no range check for subscript operator.

    ReplyDelete