Advertisement

Working WIth Binary File Input and Output

Started by October 15, 2000 10:33 AM
0 comments, last by IQComp 24 years, 2 months ago
I trying to learn how to open, read, write, and close a binary file. Well, I got the basic down, but I need some help read to the end of the file. Here is my code: ofstream out; ifstream in; char x; in.open("C:\\CountItems.txt", ios::binary); // Opens file - input out.open("C:\\ContIt.txt", ios::binary); // Opens file - output in.read((char*)&x, sizeof(char)); // Read from input file out.write((char*)&x, sizeof(char));// Write what was read from input file // Closes everything in.close(); out.close(); Edited by - IQComp on 10/15/00 10:42:17 AM
just make a loop where you read in the file until you hit EOF (end of file)

while (!(in.read((char*)&x, sizeof(char)) == eof){out.write((char*)&x, sizeof(char)); }  


Edited by - Diemonex on October 15, 2000 12:54:10 PM

Edited by - Diemonex on October 15, 2000 12:55:28 PM
Diemonex Games

This topic is closed to new replies.

Advertisement