Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ binary
I want to I/O files in binary(means in 0s and 1s).
I also want to edit these 0s and 1s of files.
I have no idea how to do that... please help me.
Posted 20-Feb-13 9:43am
Comments
Alamgirable at 20-Feb-13 14:45pm
   
OR any body tell me the best place to start working with 0s and 1s.
richcb at 20-Feb-13 15:32pm
   
That is quite comical that you think you would have to define "binary" on a programming site of this magnitude.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You have everything you need with std::ofstream, std::ifstream and std::fstream:
http://www.cplusplus.com/doc/tutorial/files/[^].
 
I hope you also know bitwise arithmetic and bitwise operators. If not, lean them. Streams give you per-byte access, so you can read a byte, extract individual bits, modify them the way you want and write the whole byte. This is one of the most basic skills all developers are supposed to master.
 
See, for example: http://www.cplusplus.com/doc/tutorial/operators/[^].
 
—SA
  Permalink  
Comments
CPallini at 20-Feb-13 15:41pm
   
5.
Sergey Alexandrovich Kryukov at 20-Feb-13 19:13pm
   
Thank you, Carlo.
—SA
Maciej Los at 20-Feb-13 16:14pm
   
Short and to the point! +5!
Sergey Alexandrovich Kryukov at 20-Feb-13 19:13pm
   
Thank you, Maciej.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You usually do not directly edit the 1s and 0s.
 
When wanting to edit a binary file, people use a Hex Editor[^] where you can edit the hexadecimal representation of the binary file.
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
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