Create and initialize vector with float number array : vector insert « Vector « C++






Create and initialize vector with float number array

  
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <vector>

using namespace std;

template <class T>
void print(T& c){
   for( typename T::iterator i = c.begin(); i != c.end(); i++ ){
      std::cout << *i << endl;
   }
}

int main( ){
   const float a[] = { 1, 1.3, 1.5, 0.9, 0.1, 0.2};

   vector<float> data( a,a + sizeof( a ) / sizeof( a[0] ) );

   cout << data.size() << " ELEMENTS\n";
   print( data  );

}
  
    
  








Related examples in the same category

1.Insert element by index
2.Insert element at specific position
3.Insert 10 duplicate value to vector
4.Insert one vector to another vector
5.Insert elements from array
6.Combine insert and end to add elements to the end of vector
7.Insert characters into vector. An iterator to the inserted object is returned
8.Appending values to Vector Containers after sorting
9.Inserts an element into a vector at given position