0
我有一个原始文件students.txt。我想。我尝试使用重命名文件studentsmodified.txt覆盖但似乎改名着覆盖文件:用其他修改覆盖原文件
rename("studentsmodified.txt","students.txt");
我该怎么办呢?
我有一个原始文件students.txt。我想。我尝试使用重命名文件studentsmodified.txt覆盖但似乎改名着覆盖文件:用其他修改覆盖原文件
rename("studentsmodified.txt","students.txt");
我该怎么办呢?
便携版使用remove
和rename
:使用MoveFileEx
function
#include <stdio.h>
...
remove("students.txt");
rename("studentsmodified.txt","students.txt");
Windows的具体版本:
#include <Windows.h>
...
MoveFileEx("studentsmodified.txt","students.txt",MOVEFILE_REPLACE_EXISTING);
检查'errno'看到失败的原因 - 可能是一个权限问题,或打开文件。 –
文件存在说错误 –
它应该适用于任何性能良好的操作系统,例如Linux操作系统。您是否可能试图在非POSIX操作系统上执行此操作,例如[Windows](https://msdn.microsoft.com/en-us/library/zw5t957f.aspx)? –