在 C++ 中,你可以使用 clear()
成员函数来清空一个 set
#include <iostream>
#include <set>
int main() {
std::set<int> my_set = {1, 2, 3, 4, 5};
std::cout << "Before clearing: " << my_set << std::endl;
my_set.clear();
std::cout << "After clearing: " << my_set << std::endl;
return 0;
}
输出结果:
Before clearing: {1, 2, 3, 4, 5}
After clearing: {}