fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. namespace SF
  5. {
  6. enum Enums {None, CanStore = 1, CanRest = 2, CanTrain = 4, OnWater = 8, OnLand = 16, CanProduce = 32, CanOperate = 64, OnWaterAndLand = OnWater|OnLand};
  7. };
  8.  
  9. typedef unsigned int StructFlags;
  10.  
  11. int main()
  12. {
  13. StructFlags structureFlags = SF::None;
  14.  
  15. structureFlags |= SF::CanStore;
  16.  
  17. structureFlags |= (SF::CanOperate | SF::CanProduce);
  18.  
  19. structureFlags |= SF::OnWaterAndLand;
  20.  
  21. if(structureFlags & SF::CanStore)
  22. std::cout << "This building can store stuff." << std::endl;
  23.  
  24. if(structureFlags & SF::CanOperate)
  25. std::cout << "This building requires people to operate it." << std::endl;
  26.  
  27. // |--- Notice the '!' to negate the result.
  28. // v
  29. if( !(structureFlags & SF::CanTrain))
  30. std::cout << "This building can NOT train people." << std::endl;
  31.  
  32. if(structureFlags & SF::OnWaterAndLand)
  33. {
  34. std::cout << "This building is on both water and land." << std::endl;
  35. }
  36. else if(structureFlags & SF::OnWater)
  37. {
  38. std::cout << "This building is only on water." << std::endl;
  39. }
  40. else if(structureFlags & SF::OnLand)
  41. {
  42. std::cout << "This building is only on land." << std::endl;
  43. }
  44. else
  45. {
  46. std::cout << "This building is not on water or land." << std::endl;
  47. }
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
This building can store stuff.
This building requires people to operate it.
This building can NOT train people.
This building is on both water and land.