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&lt;int&gt; nums = {1, 2, 3, 4, 5};
// Adding an element
nums.push_back(6);
// Iterating through the vector
for (const auto&amp; num : nums) {
    std::cout &lt;&lt; num &lt;&lt; " "; // Output: 1 2 3 4 5 6
}
std::cout &lt;&lt; std::endl;
return 0;
}

Comments

Leave a Reply

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