operator<<,>>(std::filesystem::path)
提供: cppreference.com
< cpp | filesystem | path
template< class CharT, class Traits > std::basic_ostream<CharT,Traits>& |
(1) | (C++17以上) |
template< class CharT, class Traits > std::basic_istream<CharT,Traits>& |
(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"