統計字符串中某個字符出現的次數
用標準庫算法函數“ count_if”。
1、標準庫string類型
const stringstr = “testString”;
int count = count_if( str.begin(), str.end(), bind2nd(equal_to<char>(), '某字符' );
2、CString類型
CString str = “testString”;
int count = count_if( (LPCTSTR)str, (LPCTSTR)str+str.GetLength(), bind2nd(equal_to<TCHAR>(), _T('某字符')) );