将文件从一个位置移至窗口C 的另一个位置

Move file from one location to another location in window c++

本文关键字:位置 窗口 另一个 一个 文件      更新时间:2023-10-16

使用窗口10 Visual Studio C 2015将文件移至另一个位置的简单代码。在窗口中,如何将文件从一个位置移动到另一个位置。

我在位置d: data.txt上有一个文本文件。我想将其散失更改为c: total data data.txt。

#include <cstdio>
int main (void)
{
std::rename ("old_name", "new_name");
return 0;
}

我已经使用重命名的futine用于使用移动,但它不起作用的更多详细信息https://bytes.com/topic/c/answers/132322-file-move-move-programathine

我想更改文件的位置。

更改旧名称指定的文件或目录的名称。如果OldName和NewName指定了不同的路径,并且系统支持该路径,则文件将移至新位置。

#include <stdio.h>
int main ()
{
  int result;
  char oldname[] ="D:\data.txt";
  char newname[] ="C:\datadull\newname.txt";
  result= rename( oldname , newname );
  if ( result == 0 )
    puts ( "File successfully renamed" );
  else
    perror( "Error renaming file" );
  return 0;
}