Embarcadero / Dev-Cpp

A fast, portable, simple, and free C/C++ IDE
https://www.embarcadero.com/free-tools/dev-cpp
GNU General Public License v2.0
2.53k stars 276 forks source link

Getting an error message :Out of memory #233

Open Mahakchittoda opened 2 years ago

Mahakchittoda commented 2 years ago

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…]()

pmcgee69 commented 2 years ago

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

pmcgee69 commented 2 years ago
#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;
}
Mahakchittoda commented 2 years ago

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