Ask Your Question

Revision history [back]

In general, the value pointed to by the begin() iterator should not be altered because it is simply the first element in the container. However, if you still want to alter the value, you can dereference the iterator using the * operator and assign a new value to it. For example:

vector<int> myVec = {1, 2, 3};
auto it = myVec.begin();
*it = 5; // Changes the value of the first element in the vector to 5

Note that altering the value of the first element can have unintended consequences, so it should be done with caution.