相关疑难解决方法(0)

filesystem::operator/ boost 和 std 中的不同行为

我正在尝试从 移植boost::filesystemstd::filesystem。在这个过程中,我遇到了一些代码,其中booststd似乎以不同的方式表现。

以下代码显示了该行为:

#include <iostream>
#include <filesystem>
#include <boost/filesystem.hpp>

template<typename T>
void TestOperatorSlash()
{
    const std::string foo = "Foo";
    const std::string bar = "Bar";
    const T start = "\\";
    std::string sep;
    sep += T::preferred_separator;
    const auto output = start / (foo + bar) / sep;
    std::cout << output << '\n';
}

int main(int argc, char** argv)
{
    TestOperatorSlash<std::filesystem::path>();
    TestOperatorSlash<boost::filesystem::path>();
}
Run Code Online (Sandbox Code Playgroud)

该代码给出输出:

"\\"
"\FooBar\"
Run Code Online (Sandbox Code Playgroud)

我的预期行为是boost,我不明白 会发生什么std::filesystem

为什么我得到"\\"?为什么和 …

c++ filesystems boost std

6
推荐指数
1
解决办法
410
查看次数

c ++ 14 std :: experimental :: filesystem :: v1和c ++ 17 std :: filesystem之间的区别?

我找到了这个页面,描述了c ++ 14和c ++ 17之间的变化:

https://isocpp.org/files/papers/p0636r0.html

...它链接到此页面,该页面描述了建议的文件系统更改:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0218r0.html

我浏览了它.也有小的措辞改变为标准,但唯一的代码改变我看到的是那个去掉了"实验"和"V1"部分命名空间的变化,所以"的std ::实验::文件系统:: V1"变成了"的std ::文件系统",这是预料之中的.

据我所知,命名空间路径以外的任何内容都没有改变.有没有人知道是否有其他变化?

换句话说,我正在使用gcc和-std = c ++ 14.我现在可以用std :: experimental :: filesystem编写代码,并且将来只需更改这个命名空间就可以轻松切换到-std = c ++ 17吗?

我可以找到最重要的问题是重复:

Boost文件系统和标准C++文件系统库有多相似?

现代C++的实验性功能是否可靠用于长期项目?

c++ c++14 c++17

4
推荐指数
1
解决办法
1222
查看次数

标签 统计

c++ ×2

boost ×1

c++14 ×1

c++17 ×1

filesystems ×1

std ×1