# Include <iostream>
Using namespace std;
# Include <string>
# Include <afx. h>
CString GetExtName (CString fileName ){
Int pos = fileName. Find ("."); // obtain the. Location
If (pos =-1) {// if not found, this string is directly returned.
Return fileName;
} Else {
Return GetExtName (fileName. Mid (pos + 1); // if it is found, traverse it in depth until the bottom layer
}
}
Int main ()
{
While (1)
{
String str;
Cout <"input:" <endl;
Cin> str;
CString tempFileName;
TempFileName. Format ("% s", str. c_str ());
CString tag = GetExtName (tempFileName );
If (tag. Compare ("txt") = 0)
{
Cout <"output:" <"txt" <endl;
}
Else if (tag. Compare ("wmv") = 0)
{
Cout <"output:" <"wmv" <endl;
}
Else if (tag. Compare ("exe") = 0)
{
Cout <"output:" <"exe" <endl;
}
}
Return 0;
}
Output:
View plain
Input:
11. exe
Output: exe
Input:
11.exe. wmv
Output: wmv
Input:
111.exe.wmv.txt
Output: txt
Lingxiu0613 Column