C++ 为什么反转路径是非法的

C++ Why is it illegal to reverse a path?

本文关键字:非法 路径 为什么 C++      更新时间:2023-10-16
#include <algorithm>
#include <filesystem>
int main()
{
    std::experimental::filesystem::path str("fffff/aaaa/.");    
    std::reverse(str.begin(),str.end());
    return 0;
}

我使用的是vs2015,上面的这段代码无法编译,但我仍然可以反转字符串。

#include <algorithm>
#include <filesystem>
int main()
{
    std::string str("fffff/aaaa/.");    
    std::reverse(str.begin(),str.end());
    return 0;
}

为什么?

不会编译为path::begin()path::end()返回path::iterator这是path::const_iterator的别名。

请参阅 http://en.cppreference.com/w/cpp/experimental/fs/path