Home > Back-end >  seekp not seeking to proper location?
seekp not seeking to proper location?

Time:04-23

I have the following code:

  file.open(fileName, ios::in | ios::out | ios::binary);
   // many lines later
  file.seekp(fooAddr, ios::beg);
  printf("foo_addr: %d\n", foo_addr);
  file.write((char*)fooStruct, sizeof(FooStruct));

I know that fooAddr is 128 due to the printf. Yet, for some reason, when I open the target file in my hex editor, the first byte is written at location 80.

enter image description here

Is this possible? Or is there some bug I am overlooking in my program?

I guess, for context, all my file operations are wrapped in a macro that checks if file.goodbit is not 0 (truthy), and if so -- the program immediately exits after printing an error.

CodePudding user response:

Your hex editor is displaying file offsets in hexadecimal format, not in decimal.

Decimal 128 is hex 0x80.

  • Related