Representing a Dynamically Sized Numerical Vector - C++ STL

C++ examples for STL:valarray

Description

Representing a Dynamically Sized Numerical Vector

Demo Code

#include <valarray>
#include <iostream>

using namespace std;

int main() {//from  www  . ja v  a 2s  .co  m
  valarray<int> v(3);
  v[0] = 1; v[1] = 2; v[2] = 3;
  cout << v[0] << ", " << v[1] << ", " << v[2] << endl;
  v = v + v;
  cout << v[0] << ", " << v[1] << ", " << v[2] << endl;
  v /= 2;
  cout << v[0] << ", " << v[1] << ", " << v[2] << endl;
}

Result


Related Tutorials