Mail Archives: djgpp/2001/09/24/11:22:50
Hello everyone,
I am working on a small encryption utility program. At one point in the
program I need to be able to read a file backwards. Have I missed
something specific about djgpp, or have I just over looked the obvious?
Below is a sample of the code I am attempting to use:
#include<fstream>
int main(){
// pick a file to open
char file[] = "somefile.txt";
// open the file stream in binary mode
ifstream SOURCE(file,ios::binary);
if(!SOURCE){exit(1);}
// set up a variable to hold what we read
char current = '\0';
// goto the end of the file
SOURCE.seekg( 0 , ios::end );
// get the end of the file, -1 for 0-based counting
int TheEnd = -1 * (SOURCE.tellg() - 1);
// loop through the file
for( int i = -1 ; i > TheEnd ; i-- ){
SOURCE.get(current);
cout<<current;
SOURCE.seekg( i , ios::end );
}
SOURCE.close();
return 0;
}
- Raw text -