stroustrup ppp第8章钻头 [英] stroustrup ppp chapter 8 drill headers

查看:138
本文介绍了stroustrup ppp第8章钻头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于那些从stroustrup的使用c ++的编程原理和实践中进行演练的人,我无法完成第8章演练的第一部分。这个部分的主要问题是问题的结尾,它说在Windows上,您需要在 use.cpp my.cpp 并在 use.cpp 中使用 {char cc; cin >> cc;} 才能看到您的输出。如果我们不允许 std_lib_facilities.h use.cpp ,我们如何实现这一点?

也是什么意思,当它在Windows上,您需要在项目中同时使用 use.cpp my.cpp

For those of you that have read and done the drills from stroustrup's "programming principles and practice using c++" I am having trouble doing the first part of the chapter 8 drill. The main problem I have with this part is towards the end of the question where it states "On Windows, you need to have both use.cpp and my.cpp in a project and use { char cc; cin>>cc; } in use.cpp to be able to see your output." If we aren't allowed std_lib_facilities.h for use.cpp how do we make this happen?
Also what exactly does it mean when it says "On Windows, you need to have both use.cpp and my.cpp in a project"? Let me know if I'm looking to deeply into this.


创建三个文件: my.h my.cpp use.cpp 。头文件 my.h 包含


extern int foo;

void print_foo();

void print(int);

源代码文件 my.cpp 其中 #include
my.h std_lib_facilities.h 定义 print_foo(),使用 cout print(int i)以使用 cout 打印 i 的值。


源代码文件 my.h ,定义 main()以设置的值 foo 更改为 7 ,然后使用 print_foo()打印,并使用 print()打印值99。请注意, use.cpp 不会 #include std_lib_facilities.h ,因为它不会直接使用任何这些设施。


获取这些文件并运行。在Windows上,您需要在项目中同时使用 use.cpp my.cpp ,并使用 {char cc; cin >> cc; } 可以在 use.cpp 中查看您的输出。

The source code file my.cpp which #include my.h and std_lib_facilities.h, defines print_foo() to print the value of foo using cout, and print(int i) to print the value of i using cout.

The source code file use.cpp that will #include my.h, defines main() to set set the value of foo to 7 and print it using print_foo(), and to print the value 99 using print(). Note that use.cpp does not #include std_lib_facilities.h as it doesn't directly use any of those facilities.

Get these files complied and run. On Windows, you need to have both use.cpp and my.cpp in a project and use { char cc; cin>>cc; } in use.cpp to be able to see your output.


推荐答案

{ char cc; cin>>cc; }

用于从标准输入读取字符(等待 。在VS和其他IDE中,您需要这样做只是为了看到程序的输出,否则cmd窗口会关闭太快,无法读取输出。您不需要 std_lib_facilities.h ,只需 include< iostream> main 函数。

Is for reading a character from standard input (waiting for input). In VS, and other IDEs, you need to do this just to see the output of the program otherwise the cmd window will close too fast to read the output. You don't need std_lib_facilities.h, just include <iostream> and write the code above at the end of the main function.


获取并运行这些文件。在Windows上,您需要在项目中同时使用
use.cpp和my.cpp,并使用{char cc; cin >> cc;

Get these files complied and run. On Windows, you need to have both use.cpp and my.cpp in a project and use { char cc; cin>>cc; } in use.cpp to be able to see your output.

要在Windows上编译,在VS或其他IDE,您需要包括这两个源文件。在Linux上你也需要两个,但是编译过程(makefile或g ++)显式地需要这些文件,所以对于这些文件,这些文件被强调。

To compile on windows, in VS or some other IDE, you need to include both source files. On linux you need both too, however, the compilation procedure (makefile or g++) explicitly requires these files so for windows these files are emphasized.

这篇关于stroustrup ppp第8章钻头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆