Read data from a file and save that to vector : vector push pop heap « Vector « C++






Read data from a file and save that to vector

  
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>

using namespace std;

int main( )
{
    ifstream stock_file( "data.txt" );

    vector<float> price( (istream_iterator<float>( stock_file )),istream_iterator<float>() );

    vector<float> percent_change( price.size() );
    adjacent_difference( price.begin(), price.end(),percent_change.begin() );

    copy( price.begin(), price.begin()+5,ostream_iterator<float>( cout,  "  " ) );
}
  
    
  








Related examples in the same category

1.Perform the heapsort with push_heap and pop_heap
2.Inserting Elements in a vector Using the push_back Method
3.Demonstrating the STL vector push_back functions