Namespaces
Variants

operator<<,>> (std::filesystem::path)

From cppreference.net
template < class CharT, class Traits >

friend std:: basic_ostream < CharT,Traits > &

operator << ( std:: basic_ostream < CharT,Traits > & os, const path & p ) ;
(1) (C++17 이후)
template < class CharT, class Traits >

friend std:: basic_istream < CharT,Traits > &

operator >> ( std:: basic_istream < CharT,Traits > & is, path & p ) ;
(2) (C++17 이후)

경로 p 에 대한 스트림 입력 또는 출력을 수행합니다. std:: quoted 는 이후 스트림 입력 연산자로 읽을 때 공백으로 인한 잘림을 방지하기 위해 사용됩니다.

이러한 함수 템플릿은 일반적인 unqualified lookup 또는 qualified lookup 에는 보이지 않으며, std::filesystem::path가 인자의 연관 클래스일 때에만 argument-dependent lookup 에 의해 발견될 수 있습니다. 이는 using namespace std :: filesystem ; using-directive 가 존재하는 상황에서 바람직하지 않은 변환을 방지합니다.

목차

매개변수

os - 출력을 수행할 스트림
is - 입력을 수행할 스트림
p - 삽입하거나 추출할 경로

반환값

1) os
2) is

예외

구현 정의 예외를 던질 수 있습니다.

가능한 구현

operator<<
template<class CharT, class Traits>
friend std::basic_ostream<CharT,Traits>&
    operator<<(std::basic_ostream<CharT,Traits>& os, const path& p)
{
    os << std::quoted(p.string<CharT,Traits>());
    return os;
}
operator>>
template<class CharT, class Traits>
friend std::basic_istream<CharT,Traits>&
    operator>>(std::basic_istream<CharT,Traits>& is, path& p)
{
    std::basic_string<CharT, Traits> t;
    is >> std::quoted(t);
    p = t;
    return is;
}
**참고**: HTML 태그, 속성, ` `, `
`, `` 태그 내부의 텍스트, 그리고 C++ 관련 용어는 번역하지 않고 원본 그대로 유지했습니다.

예제

#include <filesystem>
#include <iostream>
int main()
{
    std::cout << std::filesystem::current_path() << '\n';
    std::cout << std::filesystem::temp_directory_path() << '\n';
}

가능한 출력:

"/home/user"
"/tmp"

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2989 C++17 using-directive 가 존재할 때 path 로 변환 가능한 모든 것의 삽입이 허용됨 hidden friend로 변경됨