我是要读一个字符串,在从中提取一些有用的字符,
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结构中是如何表示这种控制符,大虾们告诉我吧,谢谢了!!!
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结构中是如何表示这种控制符,大虾们告诉我吧,谢谢了!!!
如case 0x0A:
case 0x0D:
这样?
break;
break
case '\n': //‘\n'表示回车
不行的话找出它们对应ascii值
...
写case 13也可。
觉得不爽的话,可以自己定义宏啊:
#ifndef CR
#define CR '\r'
#define LF '\n'
#endif然后继续用你的那段代码。