example1_basic_usage.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <vector>

int main() {
    // Create a vector of integers
    std::vector<int> myVector;

    // Add elements to the vector
    myVector.push_back(10);
    myVector.push_back(20);
    myVector.push_back(30);

    // Access and modify elements
    myVector[1] = 25;

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

    return 0;
}
Back to std_vector