<filesystem> 运算符

这些非member 运算符 std::filesystem::path 在 C++17 <filesystem> 标头中声明。 比较运算符使用 path::compare(而不是原始字符串)按泛型格式的元素比较两个路径元素。 使用该 equivalent 函数确定两个路径(例如,相对路径和绝对路径)是否引用磁盘上的同一文件或目录。

注释

此页面记录 C++17 std::filesystem 运算符。 有关 MSVC 提供 <experimental/filesystem>的历史标准运算符,请参阅 <experimental/filesystem> 运算符。

有关详细信息,请参阅文件系统导航 (C++)。

要求

标头:<filesystem>

命名 空间:std::filesystem

operator==

bool operator==(const path& left, const path& right) noexcept;

函数返回 left.compare(right) == 0。

operator!=

bool operator!=(const path& left, const path& right) noexcept;

函数返回 !(left == right)。

operator<

bool operator<(const path& left, const path& right) noexcept;

函数返回 left.compare(right) < 0。

operator<=

bool operator<=(const path& left, const path& right) noexcept;

函数返回 !(right < left)。

operator>

bool operator>(const path& left, const path& right) noexcept;

函数返回 right < left。

operator>=

bool operator>=(const path& left, const path& right) noexcept;

函数返回 !(left < right)。

operator/

path operator/(const path& left, const path& right);

函数返回 path(left) /= right。

operator<<

template <class Elem, class Traits>
basic_ostream<Elem, Traits>& operator<<(basic_ostream<Elem, Traits>& os, const path& pval);

该函数将路径作为带引号的字符串插入流中。 它将返回 os << quoted(pval.string<Elem, Traits>())。

operator>>

template <class Elem, class Traits>
basic_istream<Elem, Traits>& operator>>(basic_istream<Elem, Traits>& is, path& pval);

该函数从流中提取带引号的字符串并将其分配给 pval。 它执行:

basic_string<Elem, Traits> str;
is >> quoted(str);
pval = str;
return is;

另见

头文件引用
<filesystem>
文件系统导航 (C++)