codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ STL and vectors

C++ STL and vectors

Growable arrays.

The STL gives ready-made containers. A vector grows automatically: push_back, pop_back, size, at.

Example code

#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> v = {3, 1, 2};
  v.push_back(9);
  for (int x : v) cout << x << " ";
  cout << "size " << v.size() << endl;
  return 0;
}

Run this code in the online editor

← C++ input validationC++ list →