如何使用c ++的ofstream方法删除文件?

时间:2016-04-29 09:37:13

标签: c++

我正在使用ofstream输出到我想要在程序结束时擦除的文件。是否有一种fstream方法或任何允许我删除文件的方法?

1 个答案:

答案 0 :(得分:5)

std :: fstream不提供文件系统操作,它只提供文件操作。

您可以使用适用于大多数编译器的C stdio remove

/* remove example: remove myfile.txt */
#include <stdio.h>

int main ()
{
  if( remove( "myfile.txt" ) != 0 )
     perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );
  return 0;
}