I am not sure how to find an element in a SET and report back that it was found. Using the code below, it always returns false.
Specialty.h
Specialty.cppCode:#include <set> using namespace std; class Specialty { private: set<char*> SpecialtySet; set<char*>::iterator it; void SetSpecialty(); public: bool VerifySpecialty(char *); };
Main.cpp, If I enter "DERM" or any other code then "GP" gets set every time.Code:#include "Specialty.h" #include <set> #include <iostream> using namespace std; void Specialty::SetSpecialty () { SpecialtySet.insert("CARD"); // Cardiology SpecialtySet.insert("DERM"); // Dermatology SpecialtySet.insert("GP"); // General Practice : : SpecialtySet.insert("PSY"); // Psychiatry SpecialtySet.insert("SUR"); // Surgeon } bool Specialty::VerifySpecialty(char *spec) { bool result; it = SpecialtySet.find(spec); cout << "Test: "; cout << *it << endl; system ("pause"); if (it == SpecialtySet.end()) result = false; else result = true; return result; }
Code:Specialty Spec; char *sCode = new char [5]; : : cout << "\n Enter Specialty Code: "; cin >> sCode; if (Spec.VerifySpecialty(sCode)) room[number-1].SetCode(sCode); else room[number-1].SetCode("GP");