CPP version of 'word count'