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 또는 오류 시 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 documentation
for
rename
|
|