std::filesystem::operator/(std::filesystem::path)
From cppreference.com
< cpp | filesystem | path
| friend path operator/( const path& lhs, const path& rhs ); |
(C++17以降) | |
適切な場合は、区切り文字を使用して2つのパスコンポーネントを連結します(詳細はoperator/=を参照)。
実質的に path(lhs) /= rhs を返します。
この関数は、通常の非修飾または修飾ルックアップからは見えず、std::filesystem::path が引数に関連付けられたクラスである場合にのみ引数依存ルックアップで見つけることができます。これにより、using namespace std::filesystem; using-directive が存在する場合の望ましくない変換を防ぎます。
目次 |
[編集] パラメータ
| lhs, rhs | - | 連結するパス |
[編集] 戻り値
パス連結の結果。
[編集] 例
このコードを実行
#include <filesystem> #include <iostream> int main() { # if defined(_WIN32) // see e.g. stackoverflow.com/questions/142508 std::filesystem::path p = "C:"; std::cout << "\"C:\" / \"Users\" / \"batman\" == " << p / "Users" / "batman" << '\n'; # else // __linux__ etc std::filesystem::path p = "/home"; std::cout << "\"/home\" / \"tux\" / \".fonts\" == " << p / "tux" / ".fonts" << '\n'; # endif }
実行結果の例
Windows specific output: "C:" / "Users" / "batman" == "C:Users\\batman" Linux etc specific output: "/home" / "tux" / ".fonts" == "/home/tux/.fonts"
[編集] 不具合報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 3065 | C++17 | using-directive が存在する場合に、`path` に変換可能なすべてのものを連結することを許可しました。 | 隠しフレンドにした。 |
[編集] 関連項目
| ディレクトリセパレータでパスの末尾に要素を追加します。 (public member function) |