首页 > 编程知识 正文

c++vector用法,stic考试

时间:2023-05-05 14:56:24 阅读:108756 作者:3788

会计函数

cstlsupportsavarietyoffunctionsandtemplatestosolveproblemsindifferentways。

C STL支持多种功能和模板,以多种方式解决问题。

cSTLSTD:3360accumulate ()函数(cSTLSTD3360:accumulate ) (function ) std:accumulate ) )。 functionisusedtoaccumulateallthevaluesintherange [ first,last ] bothinclusivetoanyvariableinitial _ sum。

std : accumulate ()函数用于累计[first,last]范围内的所有值,并包括所有变量initial_sum。

defaultoperationwhiccumulatesfunctiondoisaddingupalltheelementsbutdifferentoperationscanbeperformed。

累积功能的缺省操作是将所有元素加起来,但也可以执行不同的操作。

Syntax of accumulate () function:

accumulate ()函数语法:

accumulate(start,end,initial_sum ); Here、

在此,

start : istheinitialpositionoftheiterator

start :迭代器的初始位置

最终: isthelastpositionoftheiterator。

end :迭代器的最后位置。

note : anadditionalargumentcanalsobepassedintheaccumulatefunctionwhichspecifiesthetypeofoperationtobeperformed。

注意:还可以将其他参数传递给accumulate函数,以指定要执行的操作的类型。

Syntax of accumulate () functionwithadditionalargument :

具有其他参数的accumulate (函数语法:

accumulate(start,end,initial_sum,func ); Here,funcistheadditionaloperationwhichistobeperformed。

其中,func是要执行的附加操作。

C程序演示std : accumulate ()函数示例(cprogramtodemonstrateexampleofstd 33603360 accumulate ) ) function ) # include bits///Taking initial sum as 0int sum=0; cout 'ninitialvalueofsum=' sum endl; //demonstrationofaccumulatefunction//tosumalltheelementsofthevectorsum=accumulate (vec.begin )、vec.end、vec . //changingvalueofinitial _ sumto 50 sum=50; cout 'ninitialvalueofsum=' sum endl; //demonstrationofaccumulatefunction//witheadditionalargument//hereadditionalargumentisusedto//subtractalltheelement initialsum.additionalargumentcanbe/anyvalidfunctionoroperationsum=accumulate (vec.begin ),vec 返回0; } Output

出口量

initialvalueofsum=0valueofsumafteraccumulate=45 initialvalueofsumafteraccumulatefunctionwithoptionalargument=50 从/STL/STD-accumulate-function-wit-example-in-CPP-STL.aspx翻译

会计函数

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。