c++primer Plus 6 的课后题(第二章2.6)

2.6复习题

1. c++程序的模块叫什么?

 函数

2.#include<iostream>是干什么用的?

 加载头文件iostream,标准输入输出库。

3.using namespace std;是干什么用的?

使用命名空间(std.

4. 什么语句可以打印Hello, world,并开始新的一行?

 std::cout<<”Hello, world”<<endl;

5. 什么语句可以创建名为cheeses的整型变量?

 int cheeses;

6. 将值32赋值给cheeses

 cheeses = 32;

7. 将键盘输入的值读入变量cheeses中?

 cin>>cheeses;

8. 打印”We have X varieties of cheese,”,其中Xcheeses当前的值?

cout<<”We have ”<<cheeses<<” varieties of cheese,”;

9. 下面的函数原型指出了函数的那些信息?

int froop(double t);

void rattle(int n);

int prune(void);

函数的:返回值类型,参数类型,参数个数,函数名。

10. 定义函数时,什么情况下不用return?

 返回值类型为void

11. 假设您编写的main()函数包含

cout<<”Please enter yout PIN: “;

而编译器指出cout是一个未知标识符,问题的原因可能是什么?指出3种解决方法。

原因可能是没有加载iostream头文件,或者没有使用命名空间。

解决方法1开头使用#include<iostream.h> //经过测试,新版本无法使用iostream.h

替换为1. #include<iostream> ,加上using  std::cout;

2. #include<iostream> ,加上using namespace std;

3. #include<oostream>, 使用std::cout<<


猜你喜欢

转载自blog.csdn.net/qq_41068877/article/details/80711306