pushing to an array
#include <iostream>
#include <vector>
int main() {
std::vector<int> myVector; // Declaring an empty vector to store integers
myVector.push_back(3); // Adding the integer value 3 to the end of the vector
myVector.push_back(7); // Adding the integer value 7 to the end of the vector
myVector.push_back(11); // Adding the integer value 11 to the end of the vector
return 0;
}
Explanation:
#include <iostream>
: Includes the input-output stream header file to perform input and output operations.#include <vector>
: Includes the header file for the vector container, allowing the use of vectors.std::vector<int> myVector;
: Declares an empty vector calledmyVector
capable of storing integers (int
data type).myVector.push_back(3);
: Appends the integer value3
to the end of themyVector
vector.myVector.push_back(7);
: Appends the integer value7
to the end of themyVector
vector.myVector.push_back(11);
: Appends the integer value11
to the end of themyVector
vector.return 0;
: Indicates the end of themain()
function and returns0
, indicating successful program execution to the operating system.