Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching, modifying information on binary file?

I have a binary file whose size is "x+a+y" bytes. I have some questions;

  • Without exhaustive reading x bytes, How can I jump to start point of a bytes ?
  • Without taking all of the information reside in a line and then doing required modification and finally writing new information to the same line, How can I just change "a bytes" of the data in place whose starting address is shown as P?
  • Can I put a pointer to a starting point of "a bytes" that is to P ?

Question about how data is stored in pile file;

  • Why is all of the primitive data type ( such as int ) stored in pile file preferred to be unsigned ?
  • Why is offset always chosen as unsigned int ? eX: x,a,y are known value

    ___________________________________________________________
    |                             |     |                     |
    |                             |     |                     |
    |----------> x <--------------|> a <|-------> y <---------|
                                  ^
                                  ^
                                  P
    

Platform linux

Note: If I do dublicate question, please inform me so that I can delete this question. Feel free when you command smth


1 Answers

There is a method in ifstream called seekg that moves the read-position to a specific place in the file. See http://en.cppreference.com/w/cpp/io/basic_istream/seekg.

like image 182
Some programmer dude Avatar answered Feb 04 '26 21:02

Some programmer dude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!