当前位置:   article > 正文

C++中关于count的用法总结_c++ string count

c++ string count

【华为OD机试真题 2022&2023】真题目录 @点这里@

【华为OD机试真题】信号发射和接收 &试读& @点这里@

【华为OD机试真题】租车骑绿道 &试读& @点这里@

C++中关于count的用法总结

下面是关于字符串中count的两种用法,STL容器,数组的用法类似

#include <iostream>
#include <string>
#include <algorithm> //count
using namespace std;

int main()
{
    string m = "1233445";
    //int n = count(m.data(), m.data()+m.size(),'3');
    int n = count(m.begin(), m.end(),'3');
    cout << n << endl;
    return 0;
}
//vector用法:

	cout << count(v.begin(), v.end(), 6) << endl;
//数组用法:

	cout << count(a, a + 10, 4) << endl;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/439589
推荐阅读
相关标签
  

闽ICP备14008679号