网站型销售怎么做的,沃尔沃公司网站建设,衡水网站公司,电子商务网站系统的开发设计在此示例中#xff0c;计算了字符串对象中字符的频率。 为此#xff0c;使用size()函数查找字符串对象的长度。然后for 循环迭代直到字符串末尾。 在每次迭代中#xff0c;检查字符是否出现#xff0c;如果发现#xff0c;则计数增加 1。 示例 1
#include iostream计算了字符串对象中字符的频率。 为此使用size()函数查找字符串对象的长度。然后for 循环迭代直到字符串末尾。 在每次迭代中检查字符是否出现如果发现则计数增加 1。 示例 1
#include iostream
using namespace std;int main()
{string str C Programming is awesome;char checkCharacter a;int count 0;for (int i 0; i str.size(); i){if (str[i] checkCharacter){ count;}}cout Number of checkCharacter count;return 0;
}示例 2 从下面的示例中我们可以看到用到了\0\0 是c/c 语言中的字符串结束符在ASCII字符集中对应空字符NULL数值为0。 其作用是识别字符串简化字符串处理过程。 在使用过程中要为其分配内存空间但不计入字符串长度。
#include iostreamusing namespace std;
int main()
{char c[] C programming is not easy., check m;int count 0;for(int i 0; c[i] ! \0; i){if(check c[i])count;}cout Frequency of check count;return 0;
}