温馨提示×

c++中set容器关闭的方法是什么

c++
小亿
84
2024-05-17 14:27:13
栏目: 编程语言

在C++中,通过调用set容器的clear()方法来清空set容器中的所有元素。示例代码如下:

#include <iostream>
#include <set>

int main() {
    std::set<int> mySet = {1, 2, 3, 4, 5};

    // 清空set容器
    mySet.clear();

    // 输出set容器的大小,应该为0
    std::cout << "Size of set after clearing: " << mySet.size() << std::endl;

    return 0;
}

0