64,637
社区成员
发帖
与我相关
我的任务
分享
因为map是一个双向迭代器,对=进行了重新的定义(重载)
所以通过迭代器来改变元素不大好使!
template<class InIt, class OutIt>
OutIt copy(InIt first, InIt last, OutIt x);
The template function evaluates *(x + N) = *(first + N)) once for each N in the range [0, last - first), for strictly increasing values of N beginning with the lowest value. It then returns x + N. If x and first designate regions of storage, x must not be in the range [first, last).
如果一定要用的话,得改写一下pair类!
lz可以试试~~
#include<iostream>
#include<map>
#include<string>
using namespace std;
int main()
{
map<int,string> m1,m2;
m1[0]="hello";
m1[1]="world";
m2 = m1;
cout<<m2[1]<<endl;
return EXIT_SUCCESS;
}
如果lz想用什么copy泛型函数,肯定不行,因为map内部的结构不允许!!
#include <iostream>
#include <map>
using namespace std;
void main()
{
map<int,int> map1;
map<int,int> map2(map1);
}