首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::rename

Defined in header <cstdio>

?

?

int rename( const char *old_filename, const char *new_filename );

?

?

更改文件的文件名。所指向的字符串标识该文件。old_filename。新文件名由指向的字符串标识。new_filename...

如果new_filename存在时,行为是实现定义的。

参数

old_filename

-

pointer to a null-terminated string containing the path identifying the file to rename

new_filename

-

pointer to a null-terminated string containing the new path of the file

返回值

?0?如果成功或错误值为非零。

注记

POSIX指定有关此函数的语义的许多附加细节,这些信息在C++中由std::实验性::文件系统::重命名...

二次

代码语言:javascript
复制
#include <iostream>
#include <fstream>
#include <cstdio>
int main()
{
    bool ok = std::ofstream("from.txt").put('a'); // create and write to file
    if(!ok) { std::perror("Error creating from.txt"); return 1; }
 
    int rc = std::rename("from.txt", "to.txt"); 
    if(rc) { std::perror("Error renaming"); return 1; }
 
    std::cout << std::ifstream("to.txt").rdbuf() << '\n'; // print file
}

二次

产出:

二次

代码语言:javascript
复制
a

二次

另见

rename (C++17)

moves or renames a file or directory (function)

remove

erases a file (function)

C重命名文件

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com