For example, there is such a list:

Qlist<int> int_list; for(int i = 0; i < 5; i++){ int_list.push_back(i); } 

After it has been formed, I want to change the value of the second element to 5, is it possible to do this without removeAt() and insert() ?

1 answer 1

Use the operator []

 int_list[2] = 5; 
  • Only here [2] will give the third element. - αλεχολυτ
  • @alexolut, this is a philosophical question. Where you see the first, second and third elements, I see zero, first and second =) - yrHeTaTeJlb
  • 2
    zero may be an index (offset), but not an element. - αλεχολυτ