#include <iostream>
#include <vector>
#include <string>
int main() {
std::vector<std::string> shopping_list;
shopping_list.push_back("Apples");
shopping_list.push_back("Milk");
shopping_list.push_back("Bread");
shopping_list.push_back("Cheese");
std::cout << "The list currently contains " << shopping_list.size() << " items." << std::endl;
std::cout << "The current memory capacity is at least " << shopping_list.capacity() << " slots." << std::endl;
std::cout << "\nThe first item on the list is: " << shopping_list[0] << std::endl;
std::cout << "The last item using .at() is: " << shopping_list.at(shopping_list.size() - 1) << std::endl;
std::cout << "\nHere is the full shopping list:" << std::endl;
for (const std::string& item : shopping_list) {
std::cout << "- " << item << std::endl;
}
shopping_list.pop_back();
std::cout << "\nAfter removing the last item, the new size is: "
<< shopping_list.size() << std::endl;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: