我在VS2022上想把一个文本文件的内容做修改并写入另一个文本文件,并且删除原理的文本文件,将后面的文本命名为原来前面文本文件的名字。但是执行不了,a,b均输出-1.但是相同的方法在codeblocks上可以执行。 确实执行时相关文件都没有打开,也重启过VS尝试过了
请问这是什么问题呢

在VS2022上 无法用C语言执行文件删除和重命名操作的问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 赵4老师 2022-04-21 11:19关注
remove, _wremove
Delete a file.int remove( const char *path );
int _wremove( const wchar_t *path );
Routine Required Header Compatibility
remove <stdio.h> or <io.h> ANSI, Win 95, Win NT
_wremove <stdio.h> or <wchar.h> Win NTFor additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail versionReturn Value
Each of these functions returns 0 if the file is successfully deleted. Otherwise, it returns –1 and sets errno either to EACCES to indicate that the path specifies a read-only file, or to ENOENT to indicate that the filename or path was not found or that the path specifies a directory. This function fails and returns -1 if the file is open.
rename, _wrename
Rename a file or directory.int rename( const char *oldname, const char *newname );
int _wrename( const wchar_t *oldname, const wchar_t *newname );
Routine Required Header Compatibility
rename <io.h> or <stdio.h> ANSI, Win 95, Win NT
_wrename <stdio.h> or <wchar.h> Win NTFor additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail versionReturn Value
Each of these functions returns 0 if it is successful. On an error, the function returns a nonzero value and sets errno to one of the following values:
EACCES
File or directory specified by newname already exists or could not be created (invalid path); or oldname is a directory and newname specifies a different path.
ENOENT
File or path specified by oldname not found.
EINVAL
Name contains invalid characters.
For other possible return values, see _doserrno, _errno, syserrlist, and _sys_nerr.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 Qt 不小心删除了自带的类,该怎么办
- ¥15 我需要在PC端 开两个抖店工作台客户端.(语言-java)
- ¥15 有没有哪位厉害的人可以用C#可视化呀
- ¥15 可以帮我看看代码哪里错了吗
- ¥15 设计一个成绩管理系统
- ¥15 PCL注册的选点等函数如何取消注册
- ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
- ¥15 Python爬虫程序
- ¥15 crypto 这种的应该怎么找flag?
- ¥15 代码已写好,求帮我指出错误,有偿!