#include#include using namespace std; int main() { list
myList; if(myList.empty()) //checking if list is empty { cout << "List is empty!" << endl; } else { cout << "List is not empty!" << endl; } return 0; }
List is empty!
#include#include using namespace std; int main() { list
myList = {1, 2, 3}; if(myList.empty()) //checking if list is empty { cout << "List is empty!" << endl; } else { cout << "List is not empty!" << endl; } return 0; }
List is not empty!In this example, we have declared a list with values and then checked whether it is empty using the empty() method. As it is not empty, it prints "List is not empty!". This method is part of the C++ Standard Template Library (STL) and is declared in the list header file.