寻求不寻求适当的位置?
我有以下代码:
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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的十六进制编辑器以十六进制格式显示文件偏移,而不是十进制。
十进制128是十六进制0x80。
Your hex editor is displaying file offsets in hexadecimal format, not in decimal.
Decimal 128 is hex 0x80.