Using STL Containers

This example shows how to use the Standard Template Library (STL) with a std::vector.

cppCopy code#include <iostream>
#include <vector>

int main() {
    std::vector<int> nums = {1, 2, 3, 4, 5};

    // Adding an element
    nums.push_back(6);

    // Iterating through the vector
    for (const auto& num : nums) {
        std::cout << num << " "; // Output: 1 2 3 4 5 6
    }
    std::cout << std::endl;

    return 0;
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *