switch
switch语句我用的的确不多,还是习惯写成if-else的形式。
switch 中的控制流:
    
        
            | 
             It is a common misunderstanding to expect that only the statements associated with the matched case label are executed. However, execution continues across case boundaries until the end of the switch statement or a break is encountered. 
            存在一个普遍的误解:以为程序只会执行匹配的 case 标号相关联的语句。实际上,程序从该点开始执行,并跨越 case 边界继续执行其他语句,直到 switch 结束或遇到 break 语句为止。 
             | 
        
    
有2种switch常见的错误写法:
l           case 标号必须是整型常量表达式。
l           如果两个 case 标号具有相同的值,同样也会导致编译时的错误。
Switch内部的变量定义:
对于 switch 结构,只能在它的最后一个 case 标号或 default 标号后面定义变量。
 
do while语句
用作条件判断的变量一定要定义在循环体之外,
    
        
            | 
             // repeatedly ask user for pair of numbers to sum 
            string rsp; // used in the condition; can't be defined inside the do 
            do { 
               // ... 
            } while (!rsp.empty() && rsp[0] != 'n'); 
             | 
        
    
do while 循环不可以采用如下方式定义变量:
    
        
            | 
             // error: declaration statement within do condition is not supported 
            do { 
                // ... 
                mumble(foo); 
            } while (int foo = get_foo()); // error: declaration in do condition 
             | 
        
    
不过其实自己写代码时,这个各色的写法一般是不会出现的。
 
Using the Preprocessor for Debugging(使用预处理器进行调试)
预处理器还定义了其余四种在调试时非常有用的常量:
__FILE__ 文件名
__LINE__ 当前行号
__TIME__ 文件被编译的时间
__DATE__ 文件被编译的日期
断言assert是一种预处理宏,assert 宏就求解条件表达式,如果结果为 false,assert 输出信息并且终止程序的执行。如果该表达式有一个非零(例如,true)值,则 assert 不做任何操作。