operator<<,>>(std::filesystem::path)
提供: cppreference.com
<tbody>
</tbody>
template< class CharT, class Traits > std::basic_ostream<CharT,Traits>& operator<<( std::basic_ostream<CharT,Traits>& os, const std::filesystem::path& p ); |
(1) | (C++17以上) |
template< class CharT, class Traits > std::basic_istream<CharT,Traits>& operator>>( std::basic_istream<CharT,Traits>& is, std::filesystem::path& p ); |
(2) | (C++17以上) |
パス p に対してストリーム入出力を行います。 後にストリーム入力演算子で読み込んだときに空白のせいで切り捨てられないように、 std::quoted が使用されます。
これらの関数テンプレートは通常の無修飾または修飾付きの名前探索には可視でなく、 std::filesystem::path が引数の関連クラスであるときに実引数依存の名前探索によってのみ発見されます。 これは using 指令 using namespace std::filesystem; が存在する場合の望まれない変換を防ぎます。
引数
| os | - | 出力を行うストリーム |
| is | - | 入力を行うストリーム |
| p | - | 挿入または抽出するパス |
戻り値
1)
os。2)
is。例外
(なし)
欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
| DR | 適用先 | 発行時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 2989 | C++17 | allowed insertion of everything convertible to path in the presence of a using-directive
|
made hidden friend |
実装例
| 1つめのバージョン |
|---|
template< class CharT, class Traits >
std::basic_ostream<CharT,Traits>&
operator<<( std::basic_ostream<CharT,Traits>& os, const path& p )
{
os << std::quoted(p.string<CharT,Traits>());
return os;
}
|
| 2つめのバージョン |
template< class CharT, class Traits >
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;
}
|
例
Run this code
#include <iostream>
#include <filesystem>
int main()
{
std::cout << std::filesystem::current_path() << '\n';
}
出力例:
"/home/user"