swap elements one by one of 2 vector c++ code example Example: swap two elements of a vector std::iter_swap(arr.begin()+pos1,arr.begin()+pos2);