Chanrian7 2022-04-20 21:06 采纳率: 95.4%
浏览 90
已结题

在VS2022上 无法用C语言执行文件删除和重命名操作的问题

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

img

img

img

img

  • 写回答

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 NT

    For 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 version

    Return 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 NT

    For 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 version

    Return 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 5月12日
  • 已采纳回答 5月4日
  • 创建了问题 4月20日

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助