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 netty整合springboot之后自动重连失效
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击