C++STL中algorithm常用算法函数
介绍algorithm库中的常用算法函数,应用主要包括vector和string
周一写bug,bug改一周
这个作者很懒,什么都没留下…
展开
-
C++STL中的求和函数accumulate()
C++STL中的求和函数accumulate()1.1 函数原型及描述accumulate(_InIt _First, _InIt _Last, _Ty _Val)_First和_Last累加的区间,_Val累加的初值。返回类型跟_Val一致。1.2 int中应用输出数组中的和 vector<int> testArray = { 1, 2, 3, 4 }; int s...原创 2020-02-23 10:29:33 · 4884 阅读 · 0 评论 -
C++STL中algorithm里reverse()函数及swap()函数
C++STL中algorithm里reverse()函数1.reverse()函数在string和vector中均可应用1.1函数原型及描述void reverse(_BidIt _First, _BidIt _Last)将指定范围内元素重新反序排序。应用例子 vector<int> testArray = { 1, 2, 3, 4 }; string subStr =...原创 2020-02-19 19:49:55 · 813 阅读 · 0 评论 -
C++STL中algorithm里find()函数
string模板中的find函数1.函数介绍1.1函数原型及描述函数1size_type find(const string & str, size_type pos = 0) const形参列表str:要查找的子字符串string变量,pos :要查找的起始位位置返回为参数size_type :该子字符串首次出现时其首字符的索引;否则,返回-1应用 string sub...原创 2020-02-19 19:29:54 · 524 阅读 · 0 评论 -
C++STL中algorithm里count()函数
C++中的count()函数函数原型及描述count(),存在于vector和string中,分别对单个数字和单个字符计数用法 string mainString = "Let life be beautiful like summer flowers,death like autumn leaves"; int total = count(mainString.begin(), mai...原创 2020-02-19 18:48:31 · 504 阅读 · 0 评论