Compute the difference
#include <algorithm>
#include <functional>
#include <iomanip>
#include <vector>
#include <iostream>
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 d1[] = { 1.11, 2.22, 3.33, 4.44, 5.55 };
const float d2[] = { 6.66, 7.77, 8.88, 9.99, 1.11 };
vector<float> v2( d2,d2 + sizeof( d2 ) / sizeof( d2[0] ) );
vector<float> v1( d1,d1 + sizeof( d1 ) / sizeof( d1[0] ) );
vector<float> change( v2.size() );
transform( v2.begin(), v2.end(), v1.begin(),change.begin(), minus<float>() );
print( change );
}
Related examples in the same category