I would like to copy the content of one std::map into another. Can I use std::copy
for that? Obviously, the following code won\'t work:
int main
You need a variant of an insert iterator:
std::copy(m1.begin(), m1.end(), std::inserter(m2, m2.end()) );
inserter is defined in <iterator>
. It requires a place to insert into (hence the m2.end()
), and returns an insert_iterator.
You can use GMan's answer --- but the question is, why do you want to use std::copy
? You should use the member function std::map<k, v>::insert instead.
m2.insert(m1.begin(), m1.end());