我将一些可执行文件的路径存储在 boost::filesystem::path 中。 当我尝试将它与 create_directory 等标准 boost 功能一起使用时,我发现没有任何效果。 当我打印存储在 boost::filesystem::path 中的值时,我只得到第一个字符。
const std::string path("c:\\test\\file");
boost::filesystem::path p(path);
printf("%s\n", p.c_str());
我希望在控制台中看到“c:\test\file”,但只得到“c”。
在 Linux 上,此代码按预期完美运行。在 Windows 上,我有我描述的行为。问题的根源是什么?
附言。 boost库版本为1.70
最佳答案
为了获得 std::string
而不是 跨平台的 std::wstring
,你可以使用 boost::fileystem::path::string()
而不是 c_str():
const std::string path("c:\\test\\file");
boost::filesystem::path p(path);
std::cout << p.string();
关于c++ - boost::filesystem::path 只给出第一个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56098133/