std:: remove
From cppreference.net
C++
Input/output library
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
C-style I/O
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
ヘッダーで定義
<cstdio>
|
||
|
int
remove
(
const
char
*
pathname
)
;
|
||
pathname が指す文字列で識別されるファイルを削除します。
ファイルが現在いずれかのプロセスによって開かれている場合、この関数の動作は実装定義です。POSIXシステムではファイル名(ディレクトリエントリ)のリンクを解除しますが、ファイルシステムの領域は、いずれかのプロセスで開かれている間およびファイルへの他のハードリンクが存在する間は回収されません。Windowsではこのような場合、ファイルの削除は許可されません。
目次 |
パラメータ
| pathname | - | 削除するファイルを識別するパスを含む、null終端文字列へのポインタ |
戻り値
0 成功時は0、エラー時は非ゼロの値を返します。
注記
POSIXは この関数の動作について多くの追加詳細を規定しています。
標準ライブラリはまた、一組のイテレータと値を受け取る関数テンプレート std::remove も定義しています。このオーバーロードは標準 algorithms の一つです。
例
このコードを実行
#include <cstdio> #include <cstdlib> #include <fstream> #include <iostream> int main() { // ファイルを作成し、一時ストリームオブジェクトのoperator!を使用して成功を確認 if (!std::ofstream("file1.txt").put('a')) { std::perror("Error creating file1.txt"); return EXIT_FAILURE; } std::cout << std::ifstream("file1.txt").rdbuf() << '\n'; // ファイルを出力 std::remove("file1.txt"); // ファイルを削除 if (!std::ifstream{"file1.txt"}) // 一時ストリームオブジェクトのoperator!を使用 { std::perror("Error opening deleted file"); return EXIT_FAILURE; } return EXIT_SUCCESS; }
出力例:
a Error opening deleted file: No such file or directory
関連項目
|
(C++17)
(C++17)
|
ファイルまたは空のディレクトリを削除
ファイルまたはディレクトリとそのすべての内容を再帰的に削除 (関数) |
|
ファイルの名前を変更
(関数) |
|
|
Cドキュメント
for
remove
|
|