随笔 - 0  文章 - 5  trackbacks - 0
<2025年6月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(2)

文章分类

文章档案

教育

信息学奥赛

有用网站

在线OJ

专题测试

租房信息

搜索

  •  

最新评论

功能:将当前文件夹下面所有的.ans文件改成同名的.out文件

#include<iostream>
#include
<io.h>
#include
<cstdlib>
#include
<cstdio>
#include
<string>
#include
<dir.h>
using namespace std;
string path;
const int N(100);
string oldname[N],newname[N];
int main()
{
    path
=getcwd(NULL,0);
    
if (path==""return -1;
    _finddata_t fileinfo;
    
long handle;
    
string temp=path+"\\*.ans";
    handle
=_findfirst(temp.c_str(),&fileinfo); //查找到第一个文件,文件信息存入fileinfo 
    if (handle==-1return -1;  //-1表示未找到,0表示找到 
    int n(0);
    
do{
        oldname[n]
=fileinfo.name;
        newname[n]
=fileinfo.name;
        n
++;
    }
while (_findnext(handle,&fileinfo)==0);    
    
int k,len;
    
for (int i=1;i<=n;i++)
    {
        k
=newname[i-1].size();
        newname[i
-1].replace(k-4,4,".out");  //后缀名改为.out            
        temp="ren "+oldname[i-1]+" "+newname[i-1];
        
//cout<<temp<<" ok"<<endl;
        system(temp.c_str());        
    }
    _findclose(handle);
    
//system("pause");        
    return 0;
}
posted on 2013-11-26 17:20 龙在江湖 阅读(237) 评论(0)  编辑 收藏 引用 所属分类: C++