/* * iterators-01.cc Standard Library, Iterators, exercise 1. */ #include #include #include using namespace std; int main() { string line = "Standard Library, Iterators, exercise 1."; unsigned space_count = 0; for (unsigned i = 0; i < line.size(); i++) { if (line[i] == ' ') space_count++; } cout << "space count: " << space_count << '\n'; space_count = 0; for (string::const_iterator it = line.cbegin(); it != line.cend(); ++it) { if (*it == ' ') space_count++; } cout << "space count: " << space_count << '\n'; space_count = 0; for (const auto c : line) { if (c == ' ') space_count++; } cout << "space count: " << space_count << '\n'; cout << "space count: " << count(line.cbegin(), line.cend(), ' ') << '\n'; return 0; }