#include <iostream>
using namespace std;
#include <string>
#include <afx.h>
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<<"输入:"<<endl;
cin>>str;
CString tempFileName;
tempFileName.Format(" %s", str.c_str());
CString tag = GetExtName(tempFileName);
if (tag.Compare("txt") == 0)
{
cout<<"输出:"<<"txt"<<endl;
}
else if (tag.Compare("wmv") == 0)
{
cout<<"输出:"<<"wmv"<<endl;
}
else if (tag.Compare("exe") == 0)
{
cout<<"输出:"<<"exe"<<endl;
}
}
return 0;
}
output:
输入:
11.exe
输出:exe
输入:
11.exe.wmv
输出:wmv
输入:
111.exe.wmv.txt
输出:txt