Thursday, November 11, 2010

The swap() Function

Given the following program:

   using namespace std;
   int main() {
      int i1 = 3;
      int i2 = 4;
      swap(i1, i2);
      return i1;

You would need to include <algorithm> for theprogram to compile.

Note that if what you are swapping are vectors, and you have already included <vector>, then you would not need to also include <algorithm>.

No comments:

Post a Comment