#include#include using namespace std; int main() { list
mylist = { 1, 2, 3, 4, 5 }; mylist.pop_back(); // remove the last element for (auto i : mylist) cout << i << " "; // print the list return 0; } // Output: 1 2 3 4
#includeThis code initializes a list with three characters and removes the last element using the 'pop_back' method. Finally, it prints both the original and updated lists on the console. The C++ STL 'list' package library is present in the STL header file named 'list'.#include using namespace std; int main() { list
mylist; mylist.push_back('a'); mylist.push_back('b'); mylist.push_back('c'); cout << "Original List: "; for (auto i : mylist) cout << i << " "; // print the list mylist.pop_back(); // remove the last element cout << "\nUpdated List: "; for (auto i : mylist) cout << i << " "; // print the updated list return 0; } // Output: Original List: a b c // Updated List: a b