Answers for "how to use vectors in cpp"

C++
1

what do we use c++ vectors for

hi it's me
Posted by: Guest on April-18-2022
0

vectors c++

#include <iostream>
#include <vector>
 
using namespace std;

int main()
{
    // Create a vector containing integers
   vector<int> v = { 7, 5, 16, 8 };
 
    v.push_back(25); // Adds 25 to the contents of the vector 
    v.push_back(13); // Adds 13 to the contents of the vector
 
    // Print out the contents of the vector
    cout << "v = { ";
    for (int n : v) {
        std::cout << n << ", ";
    }
    cout << "}; \n";
}
Posted by: Guest on March-05-2022

Browse Popular Code Answers by Language