std::filesystem::path:: replace_extension
|
path
&
replace_extension
(
const
path
&
replacement
=
path
(
)
)
;
|
(C++17부터) | |
확장자를 replacement 으로 교체하거나, replacement 의 기본값이 사용될 때 제거합니다.
우선, 이 경로에 extension() 가 존재하는 경우, 경로명의 일반 형식(generic-format) 뷰에서 제거됩니다.
그런 다음, 경로명의 일반 형식 뷰에 점 문자가 추가됩니다. 단, replacement 가 비어 있지 않고 점 문자로 시작하지 않는 경우에만 적용됩니다.
그런 다음 replacement 가 operator + = ( replacement ) 처럼 추가됩니다.
목차 |
매개변수
| replacement | - | 대체할 확장자 |
반환값
* this
예외
구현 정의 예외를 던질 수 있습니다.
참고 사항
replacement 의 타입은 파일 시스템 상의 객체를 나타내기 위한 것이 아님에도 불구하고, 파일 시스템 문자 인코딩을 올바르게 처리하기 위해 std::filesystem::path 입니다.
예제
#include <filesystem> #include <iomanip> #include <iostream> #include <utility> int main() { const int width1{18}, width2{11}; // columns' width std::cout << std::left << std::setw(width1) << "Path:" << std::setw(width2) << "Ext:" << "Result:\n"; for (const auto& [p, e] : { std::make_pair("/foo/bar.jpg", ".png"), {"/foo/bar.jpg", "png"}, {"/foo/bar.jpg", "."}, {"/foo/bar.jpg", ""}, {"/foo/bar.", "png"}, {"/foo/bar", ".png"}, {"/foo/bar", "png"}, {"/foo/bar", "."}, {"/foo/bar", ""}, {"/foo/.", ".png"}, {"/foo/.", "png"}, {"/foo/.", "."}, {"/foo/.", ""}, {"/foo/", ".png"}, {"/foo/", "png"}}) { std::filesystem::path path{p}, ext{e}; std::cout << std::setw(width1) << path << std::setw(width2) << ext; path.replace_extension(ext); std::cout << path << '\n'; } }
출력:
Path: Ext: Result: "/foo/bar.jpg" ".png" "/foo/bar.png" "/foo/bar.jpg" "png" "/foo/bar.png" "/foo/bar.jpg" "." "/foo/bar." "/foo/bar.jpg" "" "/foo/bar" "/foo/bar." "png" "/foo/bar.png" "/foo/bar" ".png" "/foo/bar.png" "/foo/bar" "png" "/foo/bar.png" "/foo/bar" "." "/foo/bar." "/foo/bar" "" "/foo/bar" "/foo/." ".png" "/foo/..png" "/foo/." "png" "/foo/..png" "/foo/." "." "/foo/.." "/foo/." "" "/foo/." "/foo/" ".png" "/foo/.png" "/foo/" "png" "/foo/.png"
참고 항목
|
파일 확장자 경로 구성 요소를 반환합니다
(public member function) |
|
|
파일 이름 경로 구성 요소를 반환합니다
(public member function) |
|
|
스템 경로 구성 요소를 반환합니다 (최종 확장자를 제외한 파일 이름)
(public member function) |
|
|
해당 경로 요소가 비어 있지 않은지 확인합니다
(public member function) |