get element in set c++ code example
Example 1: set and get in c++
/*Get or Set are methods to Access Private Members
for example */
class Employee {
private:
// Private attribute
int salary;
public:
// Setter
void setSalary(int s) {
salary = s;
}
// Getter
int getSalary() {
return salary;
}
};
int main() {
Employee myObj;
myObj.setSalary(50000);
cout << myObj.getSalary();
return 0;
}
Example 2: c++ find element in set
// initialize set
std::set<std::string> my_set({"foo", "bar"});
// find element in set
my_set.find("foo");