在 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: {}