这行指令出来会出来大小写的盘符,如D 或者d,似乎随机
所以利用获取到的字符串直接判断是否相等会因为盘符大小写问题判断路径不等,但其实是相等的;
所以有以下两种方法,写了代码的是验证OK的;
#include <iostream>
#include <filesystem>namespace fs = std::filesystem;bool arePathsSame(const fs::path& p1, const fs::path& p2) {return p1 == p2;
}int main() {fs::path path1 = "/home/user/file.txt";fs::path path2 = "/home/user/file.txt";if (arePathsSame(path1, path2)) {std::cout << "The paths are the same." << std::endl;} else {std::cout << "The paths are different." << std::endl;}return 0;
}
std::filesystem::equivalent - cppreference.com