C++ unordered_set delete

Introduction

To delete a value from an unordered set, we use the.erase() member function:


#include <iostream> 
#include <unordered_set> 

int main() //from   w w w. ja v  a 2s.c o  m
{ 
    std::unordered_set<int> myunorderedset = { 1, 2, 5, -4, 7, 10 }; 
    myunorderedset.erase(-4); // erase a single value 
    for (auto el : myunorderedset) 
    { 
        std::cout << el << '\n'; 
    } 
} 



PreviousNext

Related