#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:
view plain
輸入:
11.exe
輸出:exe
輸入:
11.exe.wmv
輸出:wmv
輸入:
111.exe.wmv.txt
輸出:txt
lingxiu0613的專欄