如何计算向量的向量

yil*_*lah 1 c++ stdvector

如何std::count根据最里面向量的第二个值来计算向量向量?

我将向量声明为:

vector< vector<int> > distance(data.size(),vector<int>(3)); 
Run Code Online (Sandbox Code Playgroud)

Ben*_*ley 5

你不能用std::count它。您可以使用std::count_if

std::count_if(distance.begin(), distance.end(),
    [](vector<int> const& v) { return v[1] == whatever; });
Run Code Online (Sandbox Code Playgroud)