从 exe 文件中读取的整数是多少
What's the integer read from a exe file
正如我们所知,windows上的一个普通应用程序由PE头启动,前两个字符是"MZ"。所以我有一个C++程序来打开一个exe文件并读取它。正如我预测的那样,显示的字符是"MZ"。但要读取的整数是难以理解的,每次都不一样。那么,读取的整数是多少?
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream ifs;
ifs.open("a.exe", ios::in);
char c[2];
ifs >> c[0] >> c[1];
cout << c[0] << c[1] << endl;
ifs.close();
ifs.open("a.exe", ios::in);
int i;
ifs >> i;
cout << i << endl;
ifs.close();
return 0;
}
将文件解析为整数的尝试失败,因为文件以整数中不合法的字符开头。这使得i
中以前的垃圾仍然存在。从本质上讲,您只是打印一个从未设置过值的变量的值。
尝试更改:
int i;
至:
int i = 42;
看看会发生什么。
相关文章:
- 如何反转整数参数包
- enum是C++中的宏变量还是整数变量
- 努力将整数转换为链表。不知道我在这里做错了什么
- 在 c++ 中,能够将浮点类型加 1 的最大整数是多少?
- 从 stdio 获取一行空格分隔的整数,而不知道它们是多少 (C++)
- 如何计算整数链中使用了多少次数字?
- 给定一个整数 N>0,区间 [0, 2^N) 中有多少个整数正好有 N-1 个设置位?编写一个返回正确答案的简短函数
- 如何找出在两个整数的乘积中设置了多少位(等于 1)
- 给定一个整数 M,使得 (int)C < M 的最大浮点数 C 是多少?
- 在 C/C++ 中,混合类型整数数学所需的最小类型向上转换是多少?
- 从 exe 文件中读取的整数是多少
- 双精度和超长整数的精度差是多少
- 使用 Python 编程的 32 位整数中有多少个'1'
- 0 或 1 以外的整数的布尔值是多少
- N个整数与K对数字有多少个不能相邻的排列?
- 找出一个特定整数有多少个二进制数字
- 很难实现限制每行打印多少个整数
- 计算一个整数截断符上面有多少个字符
- 有可能知道整数类型中有多少位吗
- 控制台应用程序-用户可以为c++中的整数变量输入的最高值是多少