int rename(const char *oldname, const char *newname);
参数解释:
oldname: 原文件名
newname: 新文件名(可以指定全局路径来移动文件)
返回值:
0:成功
参数解释:
oldname: 原文件名
newname: 新文件名(可以指定全局路径来移动文件)
返回值:
0:成功
-1:失败,并将全局变量errno置为错误码。
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int flag;
flag=rename("F:\\test.txt","F:\\xiaoye.txt");
//若待重命名的文件(文件夹)对应的新文件(文件夹)已存在则重命名失败。
if(flag)
cout<<"重命名失败!"<<endl;
else
cout<<"重命名成功!"<<endl;
return 0;
}