count函数计数 c++的algorithm中提供了count函数,用于在一对迭代器中寻找指定值出现的次数。 例: count(s.begin().s.end(),val); 示例代码 string s = "aabbccdd"; int ret = 0; ret += count(s.begin(),s.end(), 'a'); cout << ret << endl; //输出:2