1.p177
运算符 另一种表示方式
&& and
|| or
! not
C语言中 要包含头文件 ios646.h C++不要求使用头文件。
2.p177
字符函数库 cctype
3.p183
将枚举量当做标签
enum{ red,orange,yellow,green,blue,violet,indigo };int code;cin>>code;while(code >=red && code <=indigo)//自动提升为算术类型 { switch (code) { case red : .... }}
4.p185
break和continue语句
break 和continue语句都能使程序能够跳过部分代码。
可以在switch语句或任何循环中使用break语句,是程序跳到switch或循环后面的语句.
1.break语句:可以强制退出循环,然后继续执行循环体味的语句。
2.continue语句:执行到循环体的某处就不在继续执行后面语句了,而是跳转到循环的开始继续执行。
程序举例:
1.include<iostream>
using namespace std;
int main()
{
int i=0;
while(i<3)
{
i++;
if(i==1)
break;
cout<<"i的值为:"<<i<<endl;
}
return 0;
} 输出结果:(空)
2.include<iostream>
using namespace std;
int main()
{
int i=0;
while(i<3)
{
i++;
if(i==1)
continue;
cout<<"i的值为:"<<i<<endl;
}
return 0; 输出结果:i的值为:2
} i的值为:3
5.p188
逻辑AND表达式左边为false,则C++将不会判断右侧的表达式
6.p189
用户输入非数字,程序将拒绝,并要求用户继续输入数字。
1. 重置cin以接受新的输入
2.删除错误输入
3.提示用户再输入
while(!cin>>golf[i]){ cin.clear(); while(din.get()!='\n') continue; cout<<"请输入数字";}