C++ trying to swap values in a vector
问题 This is my swap function: template <typename t> void swap (t& x, t& y) { t temp = x; x = y; y = temp; return; } And this is my function (on a side note v stores strings) call to swap values but whenever I try to call using values in a vector I get an error. I'm not sure what I'm doing wrong. swap(v[position], v[nextposition]); //creates errors 回答1: I think what you are looking for is iter_swap which you can find also in <algorithm> . all you need to do is just pass two iterators each pointing