print set c++
To print a set in C++, you can follow these steps:
Step 1: Include the necessary header file.
#include <iostream>
#include <set>
Step 2: Define the main function.
int main() {
// code goes here
return 0;
}
Step 3: Create a set and add elements to it.
std::set<int> mySet;
mySet.insert(10);
mySet.insert(20);
mySet.insert(30);
Step 4: Iterate over the set and print its elements.
for (auto element : mySet) {
std::cout << element << " ";
}
Step 5: End the program.
return 0;
This code will create a set of integers, add some elements to it, and then iterate over the set to print each element. The output will be the elements of the set separated by spaces.