C++如何将一个vector内容赋值给另一个vector,及swap与assign区别

  #include

  #include "DebugUtility.h"

  #include

  #include

  #include

  using namespace std;

  void print(int x)

  {

  cout << x << endl;

  }

  void Swap(vector& source, vector& dest)

  {

  DebugUtility temp;

  dest.swap(source);

  }

  void Assign(vector& source, vector& dest)

  {

  DebugUtility temp;

  dest.assign(source.begin(), source.end());

  }

  int main(int argc, const char *argv[])

  {

  vector source(900000, "90");

  vector destination(1, "abc");

  Swap(source, destination);

  //source.clear();

  //for_each(destination.begin(), destination.end(), print);

  //Assign(source, destination);

  //source.clear();

  //for_each(destination.begin(), destination.end(), print);

  return 0;

  }