A std::vector is a container class in the C++ Standard Template Library (STL) 
that stores a dynamically-sized array of elements. It is similar to an array, 
but provides additional functionality such as dynamic resizing and automatic
memory management.

Here is an example of creating and using a std::vector:

Copy code
#include <vector>
#include <iostream>

int main() {
    // Create a vector of integers with an initial size of 10
    std::vector<int> myVector(10);

    // Add the numbers 1-10 to the vector
    for (int i = 0; i < 10; i++) {
        myVector[i] = i + 1;
    }

    // Print the vector
    for (int i = 0; i < myVector.size(); i++) {
        std::cout << myVector[i] << " ";
    }
    std::cout << std::endl;

    // Add the number 11 to the end of the vector
    myVector.push_back(11);

    // Print the vector
    for (int i = 0; i < myVector.size(); i++) {
        std::cout << myVector[i] << " ";
    }
    std::cout << std::endl;

    // Remove the last element from the vector
    myVector.pop_back();

    // Print the vector
    for (int i = 0; i < myVector.size(); i++) {
        std::cout << myVector[i] << " ";
    }
    std::cout << std::endl;

    return 0;
}
This program creates a std::vector called myVector with an initial size of 10.
It then uses a for loop to add the numbers 1-10 to the vector. After that it will 
print the vector, then it will add the number 11 to the end of the vector using 
the push_back() function. After that it will print the vector again, and finally 
it will remove the last element from the vector using the pop_back() function and
print the vector again, and the final output will be the vector containing numbers
1-10.

Note that a vector's size can be changed, and it will automatically allocate 
memory as needed. Also, the elements of a vector can be accessed using the [] 
operator, just like with an array.

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: