Article ID: 156807 - View products that this article applies to.
This article was previously published under Q156807
Note Microsoft Visual C++ NET 2002 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies to unmanaged Visual C++ code only.
Note Microsoft Visual C++ 2005 supports both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model.
The sample code below illustrates how to use the accumulate, copy, and vector::push_back STL functions in Visual C++.
NOTE: The class/parameter names in the prototype may not match the version in the header file. Some have been modified to improve readability.
DescriptionThe accumulate function initializes an accumulator acc with an initial value init and then modifies it with acc = acc + *i or acc = binary_op(acc,*i) for every iterator i in the range [first, last) in order.
Normally, the accumulate function is used to sum the numeric elements of a vector. However, it can also be used to do other useful work such as concatenate a vector of strings.
Program Output is:
1 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 0.111111 0.1 The sum of 1 + 1/2 + 1/3 + ... + 1/10 is 2.92897 The product of 1 * 1/2 * 1/3 * ... * 1/10 is 2.75573e-007 The concatenated vector of strings: This is one sentence.
Visual C++ Books On Line: Visual C++ Books:C/C++:Standard C++ Library Reference.
Article ID: 156807 - Last Review: January 5, 2006 - Revision: 5.0
Contact us for more help