Ich bin neu in C++ und ich versuche durch die Karte zu iterieren, während ich eine if-Anweisung übergebe. Das Programm stürzt jedoch ab.C++ - Warum stürzt das Programm mit der if-Anweisung im Map-Iterator ab?
Bitte helfen Sie mir das Programm zu reparieren.
#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <string>
#include <iterator>
using namespace std;
int main()
{
std::map<int,int> h;
std::map<int,int>::iterator it;
h[1] = 2;
h[4] = 5;
for(it = h.begin(); it !=h.end(); it++){
if (it->second > 4){
h.erase(it->first);
}
}