有没有方便的方法使用STL在容器中找到最大元素?

nha*_*123 1 c++ stl

有没有办法使用STL在容器内找到最大的容器?ATM,我有这种相当天真的方式:


int main()
{
        std::vector<std::vector<int> > v;

        ...

        unsigned int h = 0;

        for (std::vector<std::vector<int> >::iterator i = v.begin(); i != v.end(); ++i) {
                if (*i.size() > h) {
                        h = *i.size();
                }
        }
}

Gre*_*ers 17

您始终可以使用std :: max_element并传递一个自定义比较器,将两者的大小std::vector<int>作为参数进行比较.