std:: rename
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
rename
(
const
char
*
old_filename,
const
char
*
new_filename
)
;
|
||
ファイルの名前を変更します。ファイルは old_filename が指す文字列によって識別されます。新しいファイル名は new_filename が指す文字列によって識別されます。
new_filename が存在する場合、その動作は実装定義である。
目次 |
パラメータ
| old_filename | - | リネーム対象のファイルを識別するパスを含むヌル終端文字列へのポインタ |
| new_filename | - | ファイルの新しいパスを含むヌル終端文字列へのポインタ |
戻り値
0 成功時は0、エラー時は非ゼロの値を返します。
注記
POSIX はこの関数のセマンティクスに関する多くの追加詳細を規定しており、これらはC++では std::filesystem::rename によって再現されています。
例
このコードを実行
#include <cstdio> #include <cstdlib> #include <fstream> #include <iostream> int main() { if (!std::ofstream("from.txt").put('a')) // ファイルを作成して書き込み { std::perror("Error creating from.txt"); return EXIT_FAILURE; } if (std::rename("from.txt", "to.txt")) { std::perror("Error renaming"); return EXIT_FAILURE; } std::cout << std::ifstream("to.txt").rdbuf() << '\n'; // ファイルを出力 return EXIT_SUCCESS; }
出力:
a
関連項目
|
(C++17)
|
ファイルまたはディレクトリを移動または名前変更する
(関数) |
|
ファイルを削除する
(関数) |
|
|
Cドキュメント
for
rename
|
|