Dynamic Memory Allocation for fstream (binary)

This is a discussion on Dynamic Memory Allocation for fstream (binary) within the C++ Programming forums, part of the General Programming Boards category; Hi,
I am having problem allocating memory to read and write in binary mode.
The program I am working on ...

Dynamic Memory Allocation for fstream (binary)

I am having problem allocating memory to read and write in binary mode.

The program I am working on reads data from a file and write the data back to a second file. Both process are done through binary.

I set it to dynamically allocate memory based on the size of the file or size of data. However, I am encountering a weird problem. It seems I can read from any text file and write the same data to a second file. On the other hand, I the program crashes when I read data from binary file such as anything from jpeg to an executable. The program seems to crashs right before the memory allocation. I put a check sign (cout "check") right before and right after the allocation. The program seems to crash there.

Is there a particular rule that I missed when reading and writing binary files (anything other than text)? Note I save the data from the file to memory through a dynamically allocated variable. Do I need to use a string?