пишу такой код
#include <map>
#include <iostream>
using namespace std;
int main()
{
multimap<int,int> mmap;
mmap.insert(make_pair(1,2));
mmap.insert(make_pair(1,3));
mmap.insert(make_pair(2,3));
mmap.insert(make_pair(2,4));
mmap.insert(make_pair(4,3));
multimap<int,int>::iterator it;
for(it = mmap.begin(); it != mmap.end(); it++)
cout << "it->first " << it->first << " it->second " << it->second <<endl;
for(it = mmap.begin(); it != mmap.end(); it++) mmap.erase(it->first);
cout << endl;
for(it = mmap.begin(); it != mmap.end(); it++)
cout << "it->first " << it->first << " it->second " << it->second <<endl;
if(mmap.size() == 0) cout << "it->first = 0 " << " it->second = 0 " <<endl;
return 0;
}
выдает
it->first 1 it->second 2
it->first 1 it->second 3
it->first 2 it->second 3
it->first 2 it->second 4
it->first 4 it->second 3
it->first 2 it->second 3
it->first 2 it->second 4
it->first 4 it->second 3
когда пишу так
#include <map>
#include <iostream>
using namespace std;
int main()
{
multimap<int,int> mmap;
mmap.insert(make_pair(1,2));
mmap.insert(make_pair(1,3));
mmap.insert(make_pair(2,3));
mmap.insert(make_pair(2,4));
mmap.insert(make_pair(4,3));
multimap<int,int>::iterator it;
for(it = mmap.begin(); it != mmap.end(); it++)
cout << "it->first " << it->first << " it->second " << it->second <<endl;
mmap.erase(1);
mmap.erase(2);
mmap.erase(3);
mmap.erase(4);
cout << endl;
for(it = mmap.begin(); it != mmap.end(); it++)
cout << "it->first " << it->first << " it->second " << it->second <<endl;
if(mmap.size() == 0) cout << "it->first = 0 " << " it->second = 0 " <<endl;
return 0;
}
выдает
it->first 1 it->second 2
it->first 1 it->second 3
it->first 2 it->second 3
it->first 2 it->second 4
it->first 4 it->second 3
it->first = 0 it->second = 0
почему неполучается удалить все данные из малтимапа с помочью перврго способа? что не так?
зарание благодарен...