Just jumping in here to provide my end of C++ knowledge. The standard library <algorithm> contains a count function accepting iterators.
#include <string> // for std::string
#include <algorithm> // for std::count
std::string str = "hello, this world sucks";
int characterCount = str.size();
int wordCount = std::count( str.begin(), str.end(), ' ' ) + 1;
If you're using C strings (const char*) like BN2 is saying, you can use std::count as well with a small modification:
#include <algorithm> // for std::count
#include <string.h> // for strlen
const char* str = "hello, this world sucks";
int characterCount = strlen( str );
int wordCount = std::count( str, str+characterCount, ' ' ) + 1;
OR you can create a temporary std::string object and use the first method:
const char* str = "hello, this world sucks";
std::string tempString( str );
// use tempString in first method here
Note that empty strings will still output a wordCount of 1, so it might be worth checking if characterCount is 0, and if so, set wordCount to 0.
TheComet