简体   繁体   English

如何从 map 内的 STL 列表中打印找到的元素?

[英]How to print out a found element from a STL List inside of a map?

void Cinema::movieRunningAt(Movie& m, std::list<int>& movieList)
{

    map<const Movie*, std::list<int>>::iterator mov_it;
    mov_it = movie_times.find(&m);

    if (mov_it == movie_times.end())
    {
        cout << "No movie was found" << endl;
        return;
    }
    cout << mov_it->second << endl;
}

second is a list, so how do I print the found element out?第二个是一个列表,那么如何打印找到的元素呢?

cout << mov_it->second << endl;

? ?

mov_it->second is a list container print it element need again traverse mov_it->second 是一个列表容器打印它的元素需要再次遍历
Examples are as follows示例如下

map<int, list<int>> mapContainer{ {1, {1,2,3}}, {2, {2, 3, 4}} };
map<int, list<int>>::iterator it = mapContainer.find(1);
if (it != mapContainer.end())
{
    for (int element : it->second)
    {
        cout << element << endl;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM