
April 10th, 2005, 04:02 PM
|
|
Registered User
|
|
Join Date: Apr 2005
Posts: 1
Time spent in forums: 11 m 47 sec
Reputation Power: 0
|
|
|
binary fileio
I am a newbee. iam trying to open a file of any type from disk and write its content as a text file. The output should be just 0001 0110..... etc. How do i do this? I wrote something like the code below. But the output file shows "testing mze" only. What is wrong with the code? I do not have any formal programming knowledge. Please help. Thankyou
Code:
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
const char * filename = "a.exe";
int main () {
char * buffer;
long size;
ifstream file (filename, ios::in|ios::binary|ios::ate);
size = file.tellg();
file.seekg (0, ios::beg);
buffer = new char [size];
file.read (buffer, size);
file.close();
ofstream fout("output.txt");
fout << "testing" << buffer << "\n";
fout << flush;
fout.close();
cout << "the complete file is in a buffer\n";
delete[] buffer;
system("PAUSE");
return 0;
}
|