C++事例! 好一点的

来源:百度知道 编辑:UC知道 时间:2024/05/30 07:10:49
需要 一些 事例 !

//三种常用的

#include <stdio.h>
//最常用的
typedef enum
{
PRINT_A, //== 0
PRINT_B, //== 1
PRINT_C, //== 2
LAST //== 3
}PrintWhat;

//也可以自己付值
typedef enum
{
PRINT_M = 2,
PRINT_N = 3,
PRINT_O = 4,
}PrintWhat1;

//可以用作位位运算, 同时拥有PRINT_P和PRINT_R
typedef enum
{
PRINT_P = 1 << 4,
PRINT_Q = 1 << 5,
PRINT_R = 1 << 6,
}PrintWhat2;

//测试函数
void print_func1(PrintWhat1 what)
{
printf("%d\n", what);
}

void print_func2(PrintWhat2 what)
{
if(what & PRINT_P)
{
printf("p\n");
}
if(what & PRINT_Q)
{
printf("q\n");
}
if(what & PRINT_R)
{
printf("r\n");
}
}

void print_func(PrintWhat what)
{
switch (what)
{
case PRINT_A