如何在 C++ 中更改文本文件的名称? [英] How to change a text file's name in C++?

查看:93
本文介绍了如何在 C++ 中更改文本文件的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改 txt 文件的名称,但我找不到如何执行此操作.

I would like to change a txt file's name, but I can not find how to do this.

例如,我想在我的 C++ 程序中将 foo.txt 重命名为 boo.txt.

For example, I want to rename foo.txt to boo.txt in my C++ program.

推荐答案

#include (或 )并使用 重命名(或std::rename):

#include <stdio.h> (or <cstdio>) and use rename (or std::rename):

rename("oldname.txt", "newname.txt");

与流行的看法相反,它包含在标准库中,并且在一定程度上是可移植的——当然,字符串的允许内容会因目标系统而异.

Contrary to popular belief, this is included in the standard library, and is portable up to a point -- though of course the allowable contents of the strings will vary with the target system.

这篇关于如何在 C++ 中更改文本文件的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆