stl(四)------如何对map进行赋值std::map::operator=

// assignment operator with maps
#include 
#include 

int main ()
{
  std::map first;
  std::map second;

  first['x']=8;
  first['y']=16;
  first['z']=32;

  second=first;                // second now contains 3 ints
  first=std::map();  // and first is now empty

  std::cout << "Size of first: " << first.size() << '\n';
  std::cout << "Size of second: " << second.size() << '\n';
  return 0;
}

Output:
Size of first: 0
Size of second: 3

      /* using namespace std;
map ::iterator m1_pIter, m2_pIter;


map m1, m2;
typedef pair Int_Pair;


m1.insert ( Int_Pair ( 1, 10 ) );
m1.insert ( Int_Pair ( 2, 20 ) );
m1.insert ( Int_Pair ( 3, 30 ) );
m1.insert ( Int_Pair ( 4, 40 ) );
m2 = m1;

*/
可以直接利用=号操作符 进行赋值操作

你可能感兴趣的:(STL随笔)