To create a set of strings in C++, you can use the std::set container from the Standard Template Library (STL).
In this example,
<set>
header for the std::set container.string_set
to store strings.insert
member function to add strings to the set.#include <iostream>
#include <set>
#include <string>
int main() {
std::set<std::string> string_set;
string_set.insert("Apple");
string_set.insert("Banana");
string_set.insert("Orange");
string_set.insert("Grapes");
for (const auto& str : string_set) {
std::cout << str << std::endl;
}
return 0;
}
Apple Banana Grapes Orange
In this tutorial, we learned How to create a Set of Strings in C++ language with well detailed examples.