Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kuphryn

Dynamic Memory Allocation for fstream (binary)

This topic is 6066 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, 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? Kuphryn

Share this post


Link to post
Share on other sites
Advertisement
are you use getline() or sth like this? :D :D

------------------------------
Dedicate to nobody, I''m nobody

Share this post


Link to post
Share on other sites
Okay. Thanks.

I finally figure out the problem. The problem has to do with mathematics, not C++ itself.

I hear experience programmers say time and time that programming is heavy on mathematics. I got my first-hand experience with this program I am working on. It is done! I am very relieve.

Thanks everyone.

Kuphryn

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!