【问题标题】:how to delete the file using method of ofstream using c++? [duplicate]如何使用 c++ 的 ofstream 方法删除文件? [复制]
【发布时间】:2016-04-29 09:37:12
【问题描述】:

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

【问题讨论】:

标签: c++


【解决方案1】:

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 2012-12-22
    • 2016-02-14
    • 2023-04-01
    相关资源
    最近更新 更多