지도에서 값 자체가 목록이면 어떻게 표시 할 수 있습니까?지도 stl에 포함 된 목록을 표시하는 방법
키 1 값 : 1,2,3 (목록)
키 : 2 값 : 4,5,6 (목록)
void somefunction()
{
cout << "Key: " << pos->first << endl;
cout << "Value:" << pos->second << endl;
}
그러나 pos- 경우> 제 목록을 포함 , 그것을 표시하는 방법?
나는 모든 디렉토리와 해당 파일을 저장하는 기능이 있습니다.
지도를 표시하는 데 문제가 있습니다. 디버깅을하고 해당 값이 제대로 저장되는 것을 관찰했지만 표시 할 수 없습니다. map의 value 부분은 그 자체가 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_;
};
목록을 반복하고 각 요소를 인쇄하거나 하나 이상의 장소에서 필요하면'decltype (pos-> second)'에 대한 연산자 <<<를 오버로드 할 수 있습니다. – 5gon12eder
[쉼표로 인쇄 목록 C++] (http://stackoverflow.com/questions/3496982/printing-lists-with-commas-c) – 5gon12eder
목록을 표시하는 것과 똑같은 방식으로 표시 할 수 있습니다 지도에 포함되어 있지 않습니다. – user2079303