Why don't you try something along this line...
CODE
char transferFile(ifstream &in_stream)
{
ofstream out_stream;
char line[100];
out_stream.open("FileIOLAb2.txt");
// Check the outstream failed, which is what I think you meant.
if(out_stream.fail())
{
cout << " failed to open the file!!!" << endl;
exit(1);
}
// Loop through the instream and pull each line into a variable first
while (in_stream.getline(line,100)) {
// Then dump the line to the output stream
out_stream << line << endl;
}
// Don't forget to close your file after you are done transferring.
out_stream.close();
return 0;
}
In this example I added one intermediate step, dump the line to a variable and then onto the output stream. Put it in a loop and it will transfer the entire file line by line like I think you meant it too.
Give this a try and I think you will see it works pretty nicely. Oh and don't forget to close your file streams. We wouldn't want any locked up resources.
Enjoy!
"At DIC we be coding ninjas!"
This post has been edited by Martyr2: 29 Oct, 2007 - 07:38 PM