如何在C ++中更改文本文件的名称 [英] How to change a text file's name in C++
本文介绍了如何在C ++中更改文本文件的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改一个 txt
文件的名称,但是我找不到如何操作。
<例如,我想在我的C ++程序中将
foo.txt
重命名为 boo.txt
。解决方案
rename
(或 std :: rename
):
rename(oldname.txt,newname.txt);与普遍的看法相反,这是包含在标准库中的,并且可以轻松移动到一个点上 - - 虽然当然允许的字符串内容会随着目标系统的不同而变化。
I'd like to change a txt
file's name but I can't find how to do this.
For example, I want to rename foo.txt
to boo.txt
in my C++ program.
解决方案 #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屋!
查看全文