Working WIth Binary File Input and Output
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)
Edited by - Diemonex on October 15, 2000 12:54:10 PM
Edited by - Diemonex on October 15, 2000 12:55:28 PM
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
Popular Topics
Advertisement
Recommended Tutorials
Advertisement