#include
using namespace std;
#include
#include
CString GetExtName(CString fileName){
int pos=fileName.Find("."); //获取. 的位置
if(pos==-1){ //如果没有找到,直接返回该字符串
return fileName;
}else{
return GetExtName(fileName.Mid(pos+1)); //找到了的话,往深层遍历,直到最底层
}
}
int main()
{
while(1)
{
string str;
cout<<"输入:"< cin>>str; CString tempFileName; tempFileName.Format(" %s", str.c_str()); CString tag = GetExtName(tempFileName); if (tag.Compare("txt") == 0) { cout<<"输出:"<<"txt"< } else if (tag.Compare("wmv") == 0) { cout<<"输出:"<<"wmv"< } else if (tag.Compare("exe") == 0) { cout<<"输出:"<<"exe"< } } return 0; } output: view plain 输入: 11.exe 输出:exe 输入: 11.exe.wmv 输出:wmv 输入: 111.exe.wmv.txt 输出:txt lingxiu0613的专栏