我是要读一个字符串,在从中提取一些有用的字符,
m_strReceived += (char)ch;///m_strReceived 是一个CString的对象
switch(ch)
{
case '$':
checksum=0; //开始计算CheckSum
flag=0;
break;
case '*':
flag=2;
c2=checksum & 0x0f; 
c1=((checksum >> 4) & 0x0f);
if (c1 < 10) c1+= '0'; else c1 += 'A' - 10;
if (c2 < 10) c2+= '0'; else c2 += 'A' - 10;
break;
case CR: ///0DH,回车控制符
break;
case LF: ///0AH,换行控制符
m_strReceived.Empty();
break;
编译后出现如下错误:
:error C2065: 'CR' : undeclared identifier
: error C2051: case expression not constant
: error C2065: 'LF' : undeclared identifier
 : error C2051: case expression not constant
请问在switch和case结构中是如何表示这种控制符,大虾们告诉我吧,谢谢了!!!

解决方案 »

  1.   

    是不是添加在case后面?
    如case 0x0A:
      case 0x0D:
    这样?
      

  2.   

    case '\n': '\n'表示回车控制符
    break;
      

  3.   

    case '\r':   //‘\r'表示换行
    break
      

  4.   

    case '\r':   //‘\r'表示换行
    case '\n':   //‘\n'表示回车
      

  5.   

    如上
    不行的话找出它们对应ascii值
      

  6.   

    case '\r' = case 13;
    ...
      

  7.   

    写case '\r'也可,
    写case 13也可。
      

  8.   

    CR,LF是VB定义的,VC好像没有定义,你可以用'\n','\r'或者用ascII码表示。
    觉得不爽的话,可以自己定义宏啊:
    #ifndef CR
    #define CR              '\r'
    #define LF              '\n'
    #endif然后继续用你的那段代码。