Open Mahakchittoda opened 2 years ago
for ( auto i = it; it != m.end(); i++ ) // <-------- i != m.end() { . . . } return 0;
#include <map>
#include <iostream>
using namespace std;
int main()
{
map<int, string> m { { 1, "Mahak"} ,
{ 2, "Ravindra"} ,
{ 3, "Sunita"}
};
m.insert({ 4, "Chittoda" });
cout << "before erase" << endl;
for (auto i : m) {
cout << i.first << " " << i.second << endl;
}
cout << endl;
cout << "finding 14 -> " << m.count(14) << endl << endl;
m.erase(3);
cout << "after erase " << endl;
for (auto i : m) {
cout << i.first << " " << i.second << endl;
}
cout << endl;
auto it = m.find(1);
for (auto i = it; i != m.end(); i++) {
cout << (*i).first << " " << (*i).second << endl;
}
return 0;
}
Thanks
On Sun, 5 Jun 2022, 8:50 pm Paul McGee, @.***> wrote:
include
include
using namespace std; int main() { map<int, string> m { { 1, "Mahak"} , { 2, "Ravindra"} , { 3, "Sunita"} };
m.insert({ 4, "Chittoda" }); cout << "before erase" << endl; for (auto i : m) { cout << i.first << " " << i.second << endl; } cout << endl; cout << "finding 14 -> " << m.count(14) << endl << endl; m.erase(3); cout << "after erase " << endl; for (auto i : m) { cout << i.first << " " << i.second << endl; } cout << endl; auto it = m.find(1); for (auto i = it; i != m.end(); i++) { cout << (*i).first << " " << (*i).second << endl; } return 0;
}
— Reply to this email directly, view it on GitHub https://github.com/Embarcadero/Dev-Cpp/issues/233#issuecomment-1146832966, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYHTSBFLUJ7XJI2KRNERATLVNTASVANCNFSM5XUTPFMA . You are receiving this because you authored the thread.Message ID: @.***>
include
include
using namespace std; int main() { map<int,string>m; m[1]="Mahak"; m[2]="Ravindra"; m[3]="Sunita"; m.insert({4,"Chittoda"}); cout<<"before erase"<<endl; for(auto i:m) { cout<<i.first<<" "<<i.second<<endl; } cout<<"finding 14 -> "<<m.count(14)<<endl; cout<<"after erase "<<endl; m.erase(3); for(auto i:m) { cout<<i.first<<" "<<i.second<<endl;
} ![Uploading issue.png…]()