Click here to Skip to main content
11,505,486 members (37,316 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ binary VC++
How to read binary file and change it.
For example:
Every data/file in our computer have its binary source which is only 0s and 1s.
I have a binary file in which
is mostly used.i want to change

How can i do that in c++?
Posted 4-Feb-13 22:04pm
Matthew Faithfull at 5-Feb-13 4:18am
There will clearly be 3 stages to any solution.
Reading the file.
Examining and changing the data that's been read.
Writing the changed data back to the file.
I suggest you research the first stage, reading, try to adapt one of the many samples usages of istream or CFile or fread to your situation and if you can't make it work ask a specific question with some code attached to give people a good chance to help you.
anonymous10 at 5-Feb-13 4:35am
Can you please give me little bit code example.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you need to change the content of a file (that is overwrite it) then you have to:
  1. Read the file content into memory.
  2. Modify memory content.
  3. Write back modified memory content to the original file.

You may use the C++ fstream to read/write a binary file, see, for instance Input/Output with files[^] for code samples.

You may as well use the C-like functions fopen,fwrite,fread for doing the same. See, for instance fopen[^] fwrite[^], fread[^].
anonymous10 at 5-Feb-13 4:25am
Can you please give me little bit code example.
CPallini at 5-Feb-13 4:57am
You may find code samples in the documentation pages I linked in my answer.
Albert Holguin at 5-Feb-13 11:49am
Do a bit of searching online after people give you solutions... you can't expect us to spoon feed you. We post answers mostly off the top of our heads and we do it all for free because we like to help, meaning we don't like to spend a lot of time on each individual question.
Albert Holguin at 5-Feb-13 11:47am
That's pretty much it... +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 532
1 F-ES Sitecore 380
2 Richard Deeming 270
3 CHill60 245
4 Richard MacCutchan 230
0 Sergey Alexandrovich Kryukov 1,087
1 Maciej Los 625
2 Peter Leow 540
3 F-ES Sitecore 525
4 OriginalGriff 487

Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 5 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100