c++中set容器关闭的方法是什么
lewis
2024-05-12
32次阅读
在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;
}

发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。