Cześć,
mam problem z poniższym zadaniem.
Program powinien nie zwraca poprawnego wyniku i nie wiem gdzie popełniam błąd.
Mój program:
#include <iostream>
#include <map>
void function(std::map<int, int> &m, int n) {
for (auto it = m.cbegin(), next_it = it; it != m.cend(); it = next_it) {
++next_it;
if (it->second >= n)
m.erase(it);
}
}
int main() {
std::map<int, int> map {{7, 1}, {3, 8}, {5, 7}, {1, 4}, {4, 5}, {8, 3}};
function(map, 5);
for (auto pair: map) {
std::cout << pair.first << " " << pair.second << std::endl; }}
Wykonanie
Out: 1 4
Out: 7 1
Out: 8 3