fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7. std::string s;
  8. std::cin >> s;
  9. auto n = std::count(s.cbegin(), s.cend(), '1');
  10. std::cout << "the number of '1's in the string \"" << s << "\" is: " << n << "\n";
  11. }
Success #stdin #stdout 0s 3476KB
stdin
1234512345
stdout
the number of '1's in the string "1234512345" is: 2