#include <afxwin.h> #include <iostream> using namespace std; template <typename elem> BOOL cycle(elem* begin, elem* end) { while(begin <=end) { if (*begin!=*end) return FALSE; begin++; end--; } return TRUE; } int getStrLength(char* s) { for(int i=0;*s!='/0';i++,s++); // for(int i=0;*s!='/n';i++,s++);//=========== 输出结果是12362,结果错误,因为字符串结尾符是‘/0’而不是‘/n’ return i; } void main() { char* str="abcdcba"; int length=getStrLength(str); cout<<length<<endl; if(cycle(str, str+length-1)) cout<<"this is a cycle string. "; else cout<<"no cycle string. "; }