Tell me, is there such a function for the vector of integers?

    1 answer 1

    Yeah almost. There is a function that can fold. It needs to pass two additional parameters - the initial value (in the case of multiplication it is 1, this is logical) and what to do with the elements (multiply). Here is the code

    #include <iostream> // std::cout #include <functional> // std::multiplies #include <numeric> // std::accumulate #include <vector> int main () { int init = 1; std::vector<int> numbers = {10,20,30}; std::cout << std::accumulate( numbers.begin(), // Π½Π°Ρ‡Π°Π»ΠΎ для умноТСния numbers.end(),// ΠΊΠΎΠ½Π΅Ρ† для умноТСния init,// Π½Π°Ρ‡Π°Π»ΡŒΠ½ΠΎΠ΅ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ std::multiplies<int>());// готовая функция умноТСния. std::cout << '\n'; return 0; } 
    • Thanks, @KoVadim, you are a direct wizard. ____ Strange thing, my accumulate function is not in std space. ) Oh, those standards. - perfect
    • Apparently you have a bad compiler. Accidentally not in tr1 namespace? - KoVadim
    • She is in a global space. And the standard microsoft compiler from mvs 2010. - perfect