Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find with hash set

#include <unordered_set>
#include <string>
#include <iostream>

int main() {
  std::unordered_set<std::string> planets{
    {"Venus"},
    {"Earth"},
    {"Mars"},
  };

  auto it = planets.find("Earth");
  if (it != planets.end()) {
    std::cout << *it << "
";
  } else {
    std::cout << "No such planet.
";
  }

  it = planets.find("PlanetX");
  if (it != planets.end()) {
    std::cout << *it << "
";
  } else {
    std::cout << "No such planet.
";
  }
}
Source by cppbyexample.com #
 
PREVIOUS NEXT
Tagged: #find #hash #set
ADD COMMENT
Topic
Name
6+3 =