C++ set Member Functions Question

Introduction

Write a program that defines a set of integers and utilizes the set's member function to check the set's size, check whether it is empty and clear the set's content.

You can use the following code structure:

#include <iostream> 

int main() 
{ 

} 


#include <iostream> 
#include <set> 

int main() 
{ 
    std::set<int> myset = { -10, 1, 3, 5, 6, 9, 15 }; 
    std::cout << "The set's size is: " << myset.size() << '\n'; 
    std::cout << "Clearing the set..." << '\n'; 
    myset.clear(); // clear the set's content 
    if (myset.empty()) 
    { 
        std::cout << "The set is empty." << '\n'; 
    } 
    else 
    { 
        std::cout << "The set is not empty." << '\n'; 
    } 
} 



PreviousNext

Related