Creating a vector that holds integers - C++ STL

C++ examples for STL:vector

Description

Creating a vector that holds integers

Demo Code

#include <iostream>
#include <vector>
using namespace std;
int main() {//from w  w  w . java2s.c o m
   vector<int> v;
   for(int i = 0; i < 10; i++)
      v.push_back(i);
   for(int i = 0; i < v.size(); i++)
      cout << v[i] << ", ";
   cout << endl;
   for(int i = 0; i < v.size(); i++)
      v[i] = v[i] * 10; // Assignment
   for(int i = 0; i < v.size(); i++)
      cout << v[i] << ", ";
   cout << endl;
}

Result


Related Tutorials