Namespaces
Variants

std::filesystem::directory_entry:: path

From cppreference.net
const std:: filesystem :: path & path ( ) const noexcept ;
(C++17 이후)
operator const std:: filesystem :: path & ( ) const noexcept ;
(C++17 이후)

디렉토리 항목이 참조하는 전체 경로를 반환합니다.

목차

매개변수

(없음)

반환값

디렉토리 항목이 참조하는 전체 경로입니다.

예제

#include <filesystem>
#include <fstream>
#include <iostream>
namespace fs = std::filesystem;
std::string get_stem(const fs::path& p) { return p.stem().string(); }
void create_file(const fs::path& p) { std::ofstream o{p}; }
int main()
{
    const fs::path dir{"tmp_dir"};
    fs::create_directory(dir);
    create_file(dir / "one");
    create_file(dir / "two");
    create_file(dir / "three");
    for (const auto& file : fs::directory_iterator(dir))
    {
        // 명시적 변환
        std::cout << get_stem(file.path()) << '\n';
        // 암시적 변환
        std::cout << get_stem(file) << '\n';
    }
    fs::remove_all(dir);
}

가능한 출력:

two
two
one
one
three
three

참고 항목

(C++17)
경로를 나타냄
(클래스)