C++ boost::filesystem::path.parent_path()和空格
我想检查来自用户输入的路径。输入必须提供不存在的文件路径。此外,如果输入还提供目录,则这些目录必须存在 输入示例:C++ boost::filesystem::path.parent_path()和空格,c++,boost,boost-filesystem,C++,Boost,Boost Filesystem,我想检查来自用户输入的路径。输入必须提供不存在的文件路径。此外,如果输入还提供目录,则这些目录必须存在 输入示例: /existence\u dir\u a/existence\u dir\u b/existence\u file.bin使用!output.parent_path().empty()使用!output.parent_path().empty() #include <boost/filesystem.hpp> #include <iostream> #inc
/existence\u dir\u a/existence\u dir\u b/existence\u file.bin
使用!output.parent_path().empty()
使用!output.parent_path().empty()
#include <boost/filesystem.hpp>
#include <iostream>
#include <string>
#include <exception>
namespace fs = boost::filesystem;
int main(int ac, char ** av)
{
fs::path output(av[1]);
std::cout << output << std::endl;
std::cout << output.parent_path() << std::endl;
if (fs::exists(output))
{
std::string msg = output.string() + " already exists";
throw std::invalid_argument(msg);
}
if ( output.parent_path().string().size() != 0 &&
!fs::exists(output.parent_path()) )
{
std::string msg = output.parent_path().string() + " is not a directory";
throw std::invalid_argument(msg);
}
}