Please!! need help in outputing the even numbers of myvector into a file

Write your question here.
Hi guys,
I am new c++ learner, I have stuck in copying the even values of myvector into a outfile stream, the program prints the required result on screen but when you see the created file it doesn't pop up the even values of the vector.
I would appreciated if anyone could help me out in this regard. Below is my coding.




#include <iostream>
#include <vector>
#include <fstream>
#include <iterator>

using namespace std;


void even_outputfile(vector <int> &numb,int);


int main()
{

int i, size=20;
vector <int> myvector;
for (i= 0; i<size; i++)
{
myvector.push_back(i);
cout<<"[ "<<myvector[i]<<" ]";
}
std:cout<<endl<<"\n";

even_outputfile(myvector,size);

return 0;
}


void even_outputfile(vector <int> &numb, int size)
{
int i;
for(i=0; i<size; i++)//loop to read even elements of the vector
{
if(numb[i]%2!=1)
{
std::cout<<"[ "<<numb[i]<<" ]";// prints the copied vector to the screen
}
}
std::ofstream output_file;

output_file.open("even.txt");

ostream_iterator<int> output_iterator(output_file, " ");

std::copy(numb.begin(), numb.end(), output_iterator);
}
Topic archived. No new replies allowed.