vcpkg引入filesystem
时间: 2024-02-02 18:35:16 浏览: 21
要在项目中使用 C++17 的 `<filesystem>` 头文件,您需要确保使用的编译器支持 C++17 标准,并且在项目中包含 `<filesystem>` 头文件。
如果您使用的是 Visual Studio,您可以使用 vcpkg 管理第三方库,并在项目中引入vcpkg安装的C++库。这里是在 vcpkg 中安装和使用 `<filesystem>` 库的步骤:
1. 安装 vcpkg:在 Windows 系统上打开 PowerShell 窗口,使用 git 克隆 vcpkg 代码库:`git clone https://github.com/microsoft/vcpkg.git`,然后进入 vcpkg 目录,执行 `bootstrap-vcpkg.bat` 或 `bootstrap-vcpkg.sh`。
2. 安装 `<filesystem>` 库:在 PowerShell 窗口中,执行 `vcpkg install filesystem` 命令,vcpkg 会下载并编译 `<filesystem>` 库,安装到 vcpkg 的安装目录中。
3. 在 Visual Studio 项目中引入 `<filesystem>` 库:在 Visual Studio 中,打开项目属性页,选择 C/C++ -> 常规 -> 附加包含目录,添加 vcpkg 的 include 目录,例如 `C:\vcpkg\installed\x64-windows\include`。然后选择链接器 -> 常规 -> 附加库目录,添加 vcpkg 的 lib 目录,例如 `C:\vcpkg\installed\x64-windows\lib`。最后在链接器 -> 输入 -> 附加依赖项中添加 `filesystem.lib`。
现在,您的项目就可以使用 `<filesystem>` 头文件了。在代码中包含 `<filesystem>` 头文件,例如 `#include <filesystem>`,然后使用 C++17 提供的文件系统 API,如 `std::filesystem::path`、`std::filesystem::exists` 等。