M
Minkoo Seo
Hi group!
I'd like know the best way to copy a map. I can copy a list
using copy and back_inserter, but in case of map, I don't
know how.
Given the following:
#include <iostream>
#include <utility>
#include <algorithm>
#include <iterator>
#include <map>
using namespace std;
int main()
{
map<string, int> m;
map<string, int> m2;
m["a"] = 1;
m["b"] = 2;
// error!
copy(m.begin(), m.end(), back_inserter(m2));
return EXIT_SUCCESS;
}
How can I write the copy statement? If it can't be done with
copy, what is the solution that requries the smallest lines of code?
Sincerely,
Minkoo Seo
I'd like know the best way to copy a map. I can copy a list
using copy and back_inserter, but in case of map, I don't
know how.
Given the following:
#include <iostream>
#include <utility>
#include <algorithm>
#include <iterator>
#include <map>
using namespace std;
int main()
{
map<string, int> m;
map<string, int> m2;
m["a"] = 1;
m["b"] = 2;
// error!
copy(m.begin(), m.end(), back_inserter(m2));
return EXIT_SUCCESS;
}
How can I write the copy statement? If it can't be done with
copy, what is the solution that requries the smallest lines of code?
Sincerely,
Minkoo Seo