std::experimental::filesystem::path::compare

Compares the lexical representations of the path and another path.

# Declarations

int compare( const path& p ) const noexcept;

(filesystem TS)

int compare( const string_type& str ) const;

(filesystem TS)

int compare( const value_type* s ) const;

(filesystem TS)

# Parameters

# Return value

A value less than 0 if the path is lexicographically less than the given path.

# Notes

For two-way comparisons, binary operators may be more suitable.

# Example

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
 
void demo(int rc, fs::path p1, fs::path p2)
{
    if (rc < 0)
        std::cout << p1 << " < " << p2 << '\n';
    else if (rc > 0)
        std::cout << p1 << " > " << p2 << '\n';
    else if (rc == 0)
        std::cout << p1 << " = " << p2 << '\n';
}
 
int main()
{
    fs::path p1 = "/a/b/"; // as if "a/b/." for lexicographical iteration
    fs::path p2 = "/a/b/#";
    demo(p1.compare(p2), p1, p2);
    demo(p1.compare("a/b/_"), p1, "a/b/_");
}

# See also