I have been given the following exercise from my book
Write a program that takes the name of an input and two output files. The input file should hold integers. Using an istream_iterator read the input file. Using ostream_iterator, write the odd numbers into the first output file. Each value should be followed by a space. Write the even numbers into the second file. Each of these values should be placed on a seperate line.
And I have one problem
My input file has the following
int main()
{
ifstream numbersFile("input.txt");
istream_iterator<int> getNumbers(numbersFile), eof;
while (getNumbers != eof) {
int num = *getNumbers++;
ofstream out;
ostream_iterator<int> storeOdds(out, " ");
ostream_iterator<int> storeEvens(out, "\n");
if (num % 2 == 0){
out.open("even.txt");
if (out.is_open())
storeEvens = num; // problem is somewhere here
} else {
out.open("odd.txt");
if (out.is_open())
storeOdds = num; // problem is somewhere here
}
}
return 0;
}