參數解釋:
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;
}