Demonstrate slice : Valarray « Data Structure « C++






Demonstrate slice

Demonstrate slice

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

int main()
{
  valarray<int> valarrayObject(10), result;
  unsigned int i;

  for(i = 0; i < 10; i++) 
     valarrayObject[ i ] = i;

  cout << "Contents of valarrayObject: ";
  for(i = 0; i <10; i++)
    cout << valarrayObject[ i ] << " "; 
  cout << endl;

  result = valarrayObject[slice(0, 5, 2)];

  cout << "Contents of result: ";
  for(i = 0; i < result.size(); i++)
    cout << result[ i ] << " "; 

  return 0;
}


           
       








Related examples in the same category

1.Demonstrate valarray: assign value, Demonstrate valarray: assign value,
2.Demonstrate gslice() in valarrayDemonstrate gslice() in valarray