我正在尝试从 移植boost::filesystem到std::filesystem。在这个过程中,我遇到了一些代码,其中boost和std似乎以不同的方式表现。
以下代码显示了该行为:
#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 ++ 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吗?
我可以找到最重要的问题是重复: