我在strReceivedData的后面加了一位标志位(a,b,c…………)。我用下面的语句得到标志位,然后,放在switch语句中,做为判断条件:
strReceivedData.GetAt(strReceivedData.GetLength()-1)
switch (strReceivedData.GetAt(strReceivedData.GetLength()-1))
{
case 'a':
         ……
         case 'b':
         ……
         ……
         
          }
但却得不到正确的结果。
我哪儿做错了?应该怎么做呢?
问题很菜,希望哪位好心的大哥指点迷津,急用!!!!
谢谢了!!!!!

解决方案 »

  1.   

    看上去没错
    加break;
    和default语句没?
      

  2.   

    strReceivedData中的数据可能是汉字,也可能是英文,这个会不会有影响?
      

  3.   

    用标准的函数
    S.AT()试试!
      

  4.   

    帮你写了一个程序测试了一下!
    没有问题!#include <iostream>
    #include <string>
    using namespace std;int main()
    {
    string cs("helloa");
    cout<<cs<<endl;
    switch (cs.at (cs.length ()-1))
    {case 'a':
    cout<<"a"<<endl;
    break;
    default:
    cout<<"none"<<endl;
    }
    return 0;
    }
      

  5.   

    使用AfxMessageBox(strReceivedData)看看,你是否真的已经把标志位加上了?
      

  6.   

    strReceivedData.GetAt(strReceivedData.GetLength()-1)到底返回一个什么类型的值?
      

  7.   

    CString::GetAt
    TCHAR GetAt( int nIndex ) const;Return ValueA TCHAR containing the character at the specified position in the string.
    ....................是不是一个const *char类型的?
      

  8.   

    strReceivedData如果有汉字,可能GetLength 结果不对。try this:
    LPCSTR *p = (LPCSTR *) strReceivedData;
    int len = strl(p);
    switch ( p[len-1) {
    .........
    }