我在strReceivedData的后面加了一位标志位(a,b,c…………)。我用下面的语句得到标志位,然后,放在switch语句中,做为判断条件:
strReceivedData.GetAt(strReceivedData.GetLength()-1)
switch (strReceivedData.GetAt(strReceivedData.GetLength()-1))
{
case 'a':
……
case 'b':
……
……
}
但却得不到正确的结果。
我哪儿做错了?应该怎么做呢?
问题很菜,希望哪位好心的大哥指点迷津,急用!!!!
谢谢了!!!!!
strReceivedData.GetAt(strReceivedData.GetLength()-1)
switch (strReceivedData.GetAt(strReceivedData.GetLength()-1))
{
case 'a':
……
case 'b':
……
……
}
但却得不到正确的结果。
我哪儿做错了?应该怎么做呢?
问题很菜,希望哪位好心的大哥指点迷津,急用!!!!
谢谢了!!!!!
加break;
和default语句没?
S.AT()试试!
没有问题!#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;
}
TCHAR GetAt( int nIndex ) const;Return ValueA TCHAR containing the character at the specified position in the string.
....................是不是一个const *char类型的?
LPCSTR *p = (LPCSTR *) strReceivedData;
int len = strl(p);
switch ( p[len-1) {
.........
}