Omit 'return'

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...

And http://www.cplusplus.com/doc/tutorial/files/ ... under Binary files
Last edited on
Open it in binary mode. See ios_base::binary.
http://cplusplus.com/reference/iostream/ios_base/openmode/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// reading a complete binary file
#include <iostream>
#include <fstream>
using namespace 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 = new char [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.
operator<<() writes formatted data. You have binary data, so you have to use std::ostream::write().
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'.
Topic archived. No new replies allowed.