关于在 c++ 中将文件路径存储在集合 STL 中

Regarding Storing file path in set STL in c++

本文关键字:存储 STL 集合 路径 c++ 文件      更新时间:2023-10-16

我想存储目录和其中包含的文件。但是我无法将insert功能用于SET STL.我想忽略重复的目录,这些目录是由于同一位置的多个文件而出现的。下面是代码片段。我在插入功能时遇到错误。

   using path_1 = std::string; 
    using paths_1 = std::set <path_1>;

 void search()
  { 
      for (recursive_directory_iterator i("."), end; i != end; ++i)
      {
       if (!is_directory(i->path()))
       {
        paths_1.insert(i->path().parent_path());
        std::cout << i->path().parent_path() << "n";
       }
        if (!is_directory(i->path()))
       {
        files.push_back(i->path().filename());
        // std::cout << i->path().filename() << "n";
       }
      }
      for (auto f : files)
      {
       store_.save(f);
      }
}

你必须有一个std::set,像这样:

paths_1 my_paths;

然后使用该实例(而不是类型本身):

my_paths.insert(i->path().parent_path());