#include#include using namespace std; int main() { list
mylist; for (int i = 0; i < 5; i++) { mylist.push_back(i); } cout << "Before clearing the list: "; for (auto it = mylist.begin(); it != mylist.end(); ++it) { cout << *it << " "; } cout << endl; mylist.clear(); cout << "After clearing the list: "; for (auto it = mylist.begin(); it != mylist.end(); ++it) { cout << *it << " "; } cout << endl; return 0; }
Before clearing the list: 0 1 2 3 4 After clearing the list:The package/library for this function is the C++ Standard Library.