设为首页 加入收藏

TOP

比对文件后缀名
2014-11-23 23:55:14 来源: 作者: 【 】 浏览:9
Tags:比对 文件 后缀

#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的专栏

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Windows服务之启动、停止、暂停、.. 下一篇一步一步写算法(之通用数据结构..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: