文件的重命名

int rename(const char *oldname, const char *newname);
參數解釋:
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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章