Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++函数的函数问题 请参阅C++编写的以下源代码。通过提供一个输入字符串,您可以使代码打印“Hello World!”吗?不允许您修改源代码。用g++编译代码。提交输入字符串和屏幕截图,证明代码打印“Hello World!” #include <iostream> #include <cstdio> using namespace std; char *p; void f1() { char str[8]; p = str; cout << "Please enter a string:"; while (!cin.eof()) { cin.get(*p); p++; } cout << "The string you entered is:" << str << endl; } void f2() { cout << "Hello World!\n"; } int main(){ cout << sizeof(char*) << endl; cout << (void*) f2 << endl; f1(); return 0; }_C++ - Fatal编程技术网

C++函数的函数问题 请参阅C++编写的以下源代码。通过提供一个输入字符串,您可以使代码打印“Hello World!”吗?不允许您修改源代码。用g++编译代码。提交输入字符串和屏幕截图,证明代码打印“Hello World!” #include <iostream> #include <cstdio> using namespace std; char *p; void f1() { char str[8]; p = str; cout << "Please enter a string:"; while (!cin.eof()) { cin.get(*p); p++; } cout << "The string you entered is:" << str << endl; } void f2() { cout << "Hello World!\n"; } int main(){ cout << sizeof(char*) << endl; cout << (void*) f2 << endl; f1(); return 0; }

C++函数的函数问题 请参阅C++编写的以下源代码。通过提供一个输入字符串,您可以使代码打印“Hello World!”吗?不允许您修改源代码。用g++编译代码。提交输入字符串和屏幕截图,证明代码打印“Hello World!” #include <iostream> #include <cstdio> using namespace std; char *p; void f1() { char str[8]; p = str; cout << "Please enter a string:"; while (!cin.eof()) { cin.get(*p); p++; } cout << "The string you entered is:" << str << endl; } void f2() { cout << "Hello World!\n"; } int main(){ cout << sizeof(char*) << endl; cout << (void*) f2 << endl; f1(); return 0; },c++,C++,注意:-如何获得Hello World!在不编辑此代码的情况下输出 如果您正在使用UNIX,请帮助我 创建一个文件“hello.txt”,其中包含: Hello World! 编译您的代码,比如test.cpp g++ test.cpp -o test 然后执行 test < hello.txt 我没有编辑你的代码,你有一个你好世界!打印出来。欢迎访问stackoverflow.com。请花些时间阅读,特别是命名和。也请和。最后,请阅读。另外,给你这个任务的人需要阅读的不是cin.e

注意:-如何获得Hello World!在不编辑此代码的情况下输出
如果您正在使用UNIX,请帮助我

创建一个文件“hello.txt”,其中包含:

Hello World!
编译您的代码,比如test.cpp

g++ test.cpp -o test
然后执行

test < hello.txt

我没有编辑你的代码,你有一个你好世界!打印出来。

欢迎访问stackoverflow.com。请花些时间阅读,特别是命名和。也请和。最后,请阅读。另外,给你这个任务的人需要阅读的不是cin.eof与你的问题有任何关系。至于你的问题,这都是关于缓冲区溢出和可能存在的安全问题。有很多书要读,也有很多文章在互联网上关于这一点和如何做到这一点。给你这个作业的人或书应该教你一些,否则这个练习就没有意义了。我不认为这是作业的意图,而是在向世界打招呼!进入程序可能会打印Hello World!?对我来说,这似乎是一个注定要失败的练习。然后教授会给你一个令人惊讶的答案来证明他有多聪明。只有邪恶的天才才能自己解决这个问题。
8
0x400a2c
Please enter a string:The string you entered is:Hello World!