// // Example of using STL accumulate: compute product of a sequence // of numbers. // #include #include // has EXIT_SUCCESS #include #include // has accumulate() #include // has multiplies() int main(void) { cout << "Enter some numbers, ctrl-D to end:\n"; vector v; int temp; while (cin >> temp) v.push_back(temp); // Notice use of STL "multiplies" template function. // What we do here is compute the product of the numbers, // so the initial value of the "running total" (product) // should be 1, not 0. cout << "product is " << accumulate(v.begin(), v.end(), 1, multiplies()) << endl; return EXIT_SUCCESS; }