Dev-Cpp icon indicating copy to clipboard operation
Dev-Cpp copied to clipboard

Getting an error message :Out of memory

Open Mahakchittoda opened this issue 3 years ago • 3 comments
trafficstars

#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;

}
cout<<endl;
auto it=m.find(1);
for(auto i=it;it!=m.end();i++)
{
	cout<<(*i).first<<" "<<(*i).second<<endl;
}
return 0;

} Uploading issue.png…

Mahakchittoda avatar Jun 02 '22 11:06 Mahakchittoda

for ( auto i = it; it != m.end(); i++ ) // <-------- i != m.end() { . . . } return 0;

pmcgee69 avatar Jun 05 '22 15:06 pmcgee69

#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;
}

pmcgee69 avatar Jun 05 '22 15:06 pmcgee69

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: @.***>

Mahakchittoda avatar Jun 05 '22 15:06 Mahakchittoda