Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ boost::filesystem::path.parent_path()和空格_C++_Boost_Boost Filesystem - Fatal编程技术网

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);
  }
}