私はバッファ オーバーフローの問題を抱えており、hello world を印刷しようとしています。以下は私のコードですが、このファイルを別のファイルで実行すると、セグメンテーション 11 の問題が発生します。"./executable < input.cpp (これは以下のファイルです)。バッファ オーバーフローの問題を解決するために何か間違ったことをしていますか?
#include<stdio.h>
using namespace std;
main()
{
printf("A");
//00000b00
for (int i = 0; i < 4; i++)
printf("%c%c%c%c",0x00,0x0b,0x00,0x00);
}
以下は、私が hello world を印刷しようとしている実際のコードです。上記は私の入力文字列です。
#include <iostream>
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:%x\n",str);
cout << "The string you entered is:";
printf("address of a is:%x\n",&a);
cout << str << endl;
}
void f2()
{
cout << "Hello World!\n";
}
main()
{
printf("The address of function f2:%08x\n",f2);
f1();
}