   going through a string
  id like to know how many certain characters there are in a string for examplechar string = "blah blah blah"i wanna be able to go through and check each character so i can count how many b''s and a''s are in there. 
  something like this maybe? void find(const char *str,const char key){    int count=0;    for(int i=0;i<strlen(str);i++)   if(str[i]==key)  count++;    cout<<"There are "<<count<<" "<<key<<"'s found in "<<str<<end;}//find --{You fight like a dairy farmer!}   [edited by - Greatwolf on July 31, 2003 2:16:03 AM];quote:Original post by Greatwolf  something like this maybe? void find(const char *str,const char key){    int count=0;    for(int i=0;i<strlen(str);i++)   if(str[i]==key)  count++;    cout<<"There are "<<count<<" "<<key<<"''s found in "<<str<<end;}//find <br><hr><br><img src=http://www.rpgplanet.com/ff9/animgif/cactuaranim.gif>--{You fight like a dairy farmer!}   <SPAN CLASS=editedby>[edited by - Greatwolf on July 31, 2003 2:16:03 AM]</SPAN>not if internationalisation means anything to you. ;  With a C string #include <algorithm>char str[] = "blah blah blah";int len = strlen(str);int a = std::count( str, str+len, ''a'' );int b = std::count( str, str+len, ''b'' );Or with a C++ string #include <string>#include <algorithm>std::string str = "blah blah blah";int a = std::count( str.begin(), str.end(), ''a'' );int b = std::count( str.begin(), str.end(), ''b'' ); [ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ][ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]    