gpt4 book ai didi

c++ - 移除对 boost::filesystem::current_path() 的依赖

转载 作者:行者123 更新时间:2023-11-28 05:00:58 25 4
gpt4 key购买 nike

我有一行代码包含了我想删除的 boost-filesystem 1.64 库,这样我就可以从我的程序中完全删除对 Boost 的依赖。

行本身:

std::string currentPath = boost::filesystem::current_path().string();

我正在寻找能给我 std::string currentPath 的替代品可在 Windows 和 Linux 上使用 Visual C++LLVM 编译器运行。如果可能,也适用于 GCC。

可能是我看得不够仔细,但我仍在学习C++,实际上对标准库知之甚少。所以我问这个问题。

目前的解决方案是依赖:

std::experimental::filesystem::current_path();

最佳答案

我建议你拿source code from Boost ,对其进行改编/去壳并继续前进。它只不过是 getcwd() (POSIX) 和 GetCurrentDirectoryW (Windows) 的包装器。当 std::filesystem::current_path() 变得广泛可用时,您可以稍后将其丢弃。

如果您想知道 BOOST_POSIX_API 是如何设置的(在方法中引用),请查看以下代码片段:

# if defined(_WIN32) || defined(__CYGWIN__) // Windows default, including MinGW and Cygwin
# define BOOST_WINDOWS_API
# else
# define BOOST_POSIX_API
# endif

关于c++ - 移除对 boost::filesystem::current_path() 的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45988326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com