创建一个txt文件来调用f2(),而不修改代码

creating a txt file to call f2() without modiying the code

本文关键字:f2 修改 调用 代码 文件 一个 txt 创建      更新时间:2023-10-16

创建一个txt文件来调用f2()而不修改代码如何输入文件并且不修改此代码文件将具有f2()的地址,然后程序将打印"hello世界"

注意:我的f2()地址是00 40 10 14,与缓冲区溢出相反,它将被读取为14 10 40 00

#include <iostream>
#include <cstdio>
using namespace std;
int i;
unsigned int* p;
void f1() {
    int a=10;
    char str[4];
    cout << "Please enter a string:";
    while (!cin.eof()) {
        cin.get(str[i]);
        i++;
    }
    printf("address of str is:%xn",str);
    printf("address of a is:%xn",&a);
    cout << "The string you entered is:";
    cout << str << endl;
}
void f2()
{
    cout << "Hello World!n";
}
main()
{ 
    printf("The address of function f2:%08xn",f2);
    f1();
}

您可以查看缓冲区溢出的示例喜欢http://blogs.msdn.com/b/roberthorvick/archive/2004/01/16/59460.aspx