Counting is as simple as calling std::count:
Code:
#include <iostream>
#include <algorithm>
// Returns how many elements an array has.
template<class T> inline size_t elems(const T& array) {
return sizeof array / sizeof *array;
}
int main() {
char line[] = "Hello world! This sentence contains some blanks.";
// You call cout with a range and a value to count.
// So std::count(line, line + elems(line), ' ') will count
// all ' ' in the range [line; line + elems(line))
std::cout << line << "\nThe above line conains "
<< std::count(line, line + elems(line), ' ') << " blanks.";
}