I am trying to read from a HEX file and copy the data with some modifications into another file.My problem is that the HEX file has '0a' and '0d' for line feed and carriage return and vc++ removes this while copying to the new file. I want to keep them. Is there anyway I can do this?
Couldn't you just explicitly write them to the file yourself? Meaning you check the input and then write '0a'/'0d' to the file it they appear. R0mai's post...
// reading a complete binary file
#include <iostream>
#include <fstream>
usingnamespace std;
ifstream::pos_type size;
char * memblock;
int main () {
ifstream file ("c:\\usethis.pcap", ios::in|ios::binary|ios::ate);
ofstream ofile ("c:\\result.txt");
if (file.is_open())
{
size = file.tellg();
memblock = newchar [size];
file.seekg (0, ios::beg);
file.read (memblock, size);
ofile << memblock;
file.close();
ofile.close();
cout << "the complete file content is in memory";
delete[] memblock;
}
else cout << "Unable to open file";
return 0;
}
Thank you for guiding me to that page. I used the code there to just copy the file as it is. And after copying I am only getting a few characters of the first line. Not the whole file.
With ofile.write(memblock, size);, deletes the first few characters from the line.
I am actually trying to read a pcap file using C++. So I am reading it as such and VC++ reads it nice in HEX. When it outputs the data it removes '0a' and '0d'. I was able to insert these manually after each line. But the problem is that the pcap file has just '0a' in the first line, even if I enter char(10), the compiler automatically prints a '0a' preceded with a '0d'.