Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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++ 如何显示地图stl中包含的列表_C++_File_Stl - Fatal编程技术网

C++ 如何显示地图stl中包含的列表

C++ 如何显示地图stl中包含的列表,c++,file,stl,C++,File,Stl,在地图中,如果值本身是一个列表,那么我们如何显示它 键:1值:1,2,3列表 键:2值:4,5,6列表 void somefunction() { cout << "Key: " << pos->first << endl; cout << "Value:" << pos->second << endl; } 但是如果pos->second包含一个列表,如何显示它 我有一个存储所有目录及其相应

在地图中,如果值本身是一个列表,那么我们如何显示它

键:1值:1,2,3列表

键:2值:4,5,6列表

void somefunction()

{
    cout << "Key: " << pos->first << endl;
    cout << "Value:" << pos->second << endl;
}
但是如果pos->second包含一个列表,如何显示它

我有一个存储所有目录及其相应文件的函数

我在显示地图的价值时遇到了问题。我已经调试并观察到相应的值被正确存储,但我无法显示它。因为映射的值部分本身就是pathiterator的列表。每当我在不同的目录中获得相同的文件名时,我都会将引用或pathiterator存储在对应于相同密钥文件名的映射中

class FileMgr
{
    public:
    using path_1 = std::string;
    using paths_1 = std::set<path_1>;
    using pathiter = paths_1::iterator;
    using listofiter = std::list<pathiter>;
    using file = std::string;
    using store = std::map<file, listofiter>;
    using store_iter = store::iterator;
    paths_1 pp;
    pathiter oo;
    listofiter l1;
    store s6;
    store_iter d;
  void addPattern(const std::string& patt)
  {
    if (patterns_.size() == 1 && patterns_[0] == "*.*")
      patterns_.pop_back();
    patterns_.push_back(patt);
  }
  void search()
  {

      for (recursive_directory_iterator i("."), end; i != end; ++i)
      {
          pp.insert(i->path().parent_path());
          oo = pp.find(i->path().parent_path());

          if (!is_directory(i->path()))
          {
              s6[i->path().filename()].push_back(oo);
          }
      }
      for ( d = s6.begin(); d != s6.end(); d++)
      {
          cout << "Key: " << d->first << "  Value: ";
          std::cout << "Value:";
          for (auto& x : d->second)
              std::cout << ' ' << x;
                                //^^Red Squiggly here ERROR
          std::cout << '\n';

      }
  }
private:
  std::string path_;
  DataStore& store_;
  patterns patterns_;
};
如果映射在int和std::list之间


将在键处显示整个列表。

不要让地图方面分散您的注意力-您只需使用pos->second,否则您将使用任何列表对象-如下所示:

std::cout << "Value:";
for (auto& x : pos->second)
    std::cout << ' ' << x;
std::cout << '\n';

<席>我是在map

中遍历每个列表的迭代器,可以循环列表并打印每个元素或重载操作符,可能的副本可以以与显示不包含在地图中的列表的方式完全相同的方式显示。在XI AM中添加红色代码片段,添加代码片段。请看我哪里出错了。非常感谢!错误提示:没有运算符@tanz您确定列表中包含整数吗?@tanz那么您为什么希望它显示类似于1,2,3的内容?你需要找出你正在使用的类型。那么,显示值应该很简单。
std::cout << "Value:";
for (auto& x : pos->second)
    std::cout << ' ' << x;
std::cout << '\n';
list<int> l;
map<int,list<int> > m;
.
.
.
.
list<int>::iterator i;
map<int,list<int> > ::iterator mitr=m.begin();

while(mitr!=m.end())
{
   l=mitr->second;
   i=l.begin();
   while(i!=l.end())
   {
        cout<<*i<<" ";
        i++;
   } 
   mitr++;
}