1、使用标准库函数count_if

2、此函数所需要的头文件

#include <algorithm>
#include <functional>

3、例子

例如有一个字符串

CString m_EditSendData;

m_EditSendData.Format(_T("%s"), _T("123 456 789") );

int nCount = std::count_if((LPCTSTR)m_EditSendData, (LPCTSTR)m_EditSendData + m_EditSendData.GetLength(),std::bind2nd(std::equal_to<char>(),' ' ));//计算空格数量

这样得到的结果nCount 就是字符串中所含有的空格字符的个数

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
猜你喜欢
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案