Difference between revisions of "CPP/C++0x/UnorderedSet"

From ProgrammingExamples
< CPP
Jump to: navigation, search
(Created page with '==UnorderedSet.cpp== <source lang="cpp"> #include <iostream> #include <unordered_set> // must use -std=c++0x flag int main(int argc, char* argv[]) { // Create a set std::u…')
 
(UnorderedSet.cpp)
 
Line 19: Line 19:
  
 
   // Output all of the elements in the set
 
   // Output all of the elements in the set
   for(std::unordered_set<unsigned int>::iterator it1 = S.begin(); it1 != S.end(); it1++)
+
   for(auto it1 = S.cbegin(); it1 != S.cend(); it1++)
 
   {
 
   {
 
     std::cout << " " << *it1;
 
     std::cout << " " << *it1;

Latest revision as of 15:07, 20 July 2011

UnorderedSet.cpp

#include <iostream>
#include <unordered_set>
 
// must use -std=c++0x flag
 
int main(int argc, char* argv[])
{
  // Create a set
  std::unordered_set<unsigned int> S;
 
  // Add 10 elements to the set
  for(unsigned int i = 0; i < 10; i++)
  {
    S.insert(i);
  }
 
  // Output all of the elements in the set
  for(auto it1 = S.cbegin(); it1 != S.cend(); it1++)
  {
    std::cout << " " << *it1;
  }
 
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(UnorderedSet)
ADD_EXECUTABLE(UnorderedSet UnorderedSet.cpp)