0
How can I apply built in function count( ) to the 3D array?
I declared a 3D vector vector<vector<vector<char>>>. If I think of this 3D vector as two 2D vectors divided in two layers (each 2D vector is in its own layer), how can I count number of times an element appears only in that layer using std::count( ) from library algorithm?
1 Resposta
0
If you want to count the total number of times a value appears in a two-dimensional vector, you could use std::count() in combination with std::accumulate(), e.g.
std::accumulate (
layer.cbegin(),
layer.cend(),
0,
[] (
const unsigned int sum,
const std::vector< char >& v
) {
return ( sum + std::count( v.cbegin(), v.cend(), YourValue ) );
}
);