c ++文件系统:std :: mismatch segfault

时间:2019-01-30 13:11:24

标签: filesystems c++17

我正在使用两个std::filesystem::path实例,我想在这些实例上应用std :: mismatch。 这两个路径实例之一是另一个的子目录,我想使用std :: mismatch来使迭代器到达位置不同的位置。

例如

void filesystem_mismatch() {
    const std::filesystem::path path{"/a/b/file"};
    const std::filesystem::path prefix{"/a/b"};
    auto tmp = std::mismatch(path.begin(), path.end(), prefix.begin());
    std::cout << *(tmp.first) << std::endl;
}

如果执行此功能,则一切正常,但是如果执行以下操作:

void filesystem_mismatch2() {
    const std::filesystem::path path{"/a/b/c/file"};
    const std::filesystem::path prefix{"/a/b/c"};
    auto tmp = std::mismatch(path.begin(), path.end(), prefix.begin());
    std::cout << *(tmp.first) << std::endl;
}

首先取消引用迭代器tmp.first时,就会出现段错误。

我在这里做错了什么? 我正在使用g ++ 8.2.0并链接到libstdc ++。so.6.25

顺便说一句,我已经在coliru中创建了一个有效的示例,但该错误并未发生。

https://coliru.stacked-crooked.com/a/deb0d007041db603

0 个答案:

没有答案