Hi,
I've been learning about the std::copy function in the <algorithm> header and I'm stuck on this exercise that I gave my self.
Let's see the code snippet first:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
ostream& operator<<(ostream& os, const int p_val)
{
os.put( p_val*2);
return os;
}
int main(/*const int argc,const char* const argv[]*/)
{
std::vector<int> myVector = {34,54,43,2,7,87};
std::copy(myVector.begin(), myVector.end(), ostream_iterator<int>(std::cout, " "));
cin.get();
return 0;
}
Basically what I'm trying to achieve is: I have a vector full of integers. I want to print the mutiply of 2 of these integers to std::cout using std::copy(). I learnt that I would have to overload operator<<(). But as you can see from my failed attempt above, I'm at a complete lost as to what I need to do insife operator<<().
Any help's much appreciated.
Cheers,
Ben