fork download
  1. #include <algorithm>
  2. #include <string>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. size_t vec_char_count(const std::vector<std::string>& vec, char c) {
  7. size_t count = 0;
  8. for (auto& str : vec) {
  9. count += std::count(str.begin(), str.end(), c);
  10. }
  11. return count;
  12. }
  13.  
  14. int main() {
  15. std::vector<std::string> vec {
  16. "hello\nworld\n",
  17. "pizza\n"
  18. };
  19. std::cout << vec_char_count(vec, '\n') << "\n";
  20. }
  21.  
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
3