Summing function of accumulate C ++ STL ()

Summing function of accumulate C ++ STL ()

1.1 Description and function prototypes

accumulate(_InIt _First, _InIt _Last, _Ty _Val)

_FirstAnd _Lastaccumulation interval, _Valthe accumulated initial values.
The return type with _Valthe same.

1.2 int application

And an output array

	vector<int> testArray = { 1, 2, 3, 4 };
	int sumT = accumulate(testArray.begin(), testArray.end(), 0);

1.2 string in the application

The char type is string type splicing

	vector<char> testChr = { 'l', 'h', 'k' };
	string strSum = accumulate(testChr.begin(), testChr.end(), (string)" ");	\\sunT = "lhk"
Published 13 original articles · won praise 1 · views 297

Guess you like

Origin blog.csdn.net/qq_38670588/article/details/104455535