#include#include using namespace std; int main() { vector v = {1, 2, 3, 4, 5}; // printing vector elements for (auto i = v.begin(); i != v.end(); i++) cout << *i << " "; return 0; }
#includeThis code initializes a vector with elements "apple", "banana", "cherry", and "date". The begin() function is used to get the iterator of the first element and the sort() function is used to sort the vector elements in alphabetical order. A for loop is then used to print the sorted vector elements. Package/library: Standard Template Library (STL)#include #include using namespace std; int main() { vector v = {"apple", "banana", "cherry", "date"}; // sorting vector elements sort(v.begin(), v.end()); // printing sorted vector elements for (auto i = v.begin(); i != v.end(); i++) cout << *i << " "; return 0; }