To check if two sets are equal in C++, you can use the '==' operator to compare them element-wise.
In this example,
set1
and set2
, containing elements of the sets.#include <iostream>
#include <set>
int main() {
std::set<int> set1 = {1, 2, 3, 4};
std::set<int> set2 = {1, 2, 3, 4};
bool areEqual = (set1 == set2);
std::cout << std::boolalpha << areEqual;
return 0;
}
true
In this example,
set1
and set2
, containing elements of the sets.#include <iostream>
#include <set>
int main() {
std::set<int> set1 = {1, 2, 3, 4};
std::set<int> set2 = {4, 3, 2, 1};
bool areEqual = (set1 == set2);
std::cout << std::boolalpha << areEqual;
return 0;
}
false
In this tutorial, we learned How to check if Two Sets are Equal in C++ language with well detailed examples.