2016-04-29 13 views
4

私は、ファイルの出力にofstreamを使用しています。このファイルは、プログラムの最後に消去したいファイルです。ファイルを削除できるfstreamなどの方法がありますか?ofstream of C++を使用してファイルを削除する方法は?

+4

[ファイルシステムライブラリ](http://en.cppreference.com/w/cpp/experimental/fs)可能なC +で+17。今のところ、[Boost](http://www.boost.org/doc/libs/1_60_0/libs/filesystem/doc/index.htm)を使うか、プラットフォーム特有のapiに固執することができます。 –

答えて

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; 
} 
関連する問題