寻求不寻求适当的位置?

发布于 2025-01-23 11:21:11 字数 616 浏览 2 评论 0原文

我有以下代码:

  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));

我知道fooaddr由于printf而为128。 但是,由于某些原因,当我在十六进制编辑器中打开目标文件时,第一个字节是在位置80写的。

“在此处输入图像说明”

这是可能的吗?还是我在程序中忽略了一些错误?

我想,对于上下文,我所有的文件操作都包裹在一个宏中,该宏检查是否file.goodbit不是0(真相),如果是,则该程序在打印错误后立即退出。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可遇━不可求 2025-01-30 11:21:11

您的十六进制编辑器以十六进制格式显示文件偏移,而不是十进制。

十进制128是十六进制0x80。

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

Decimal 128 is hex 0x80.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文