fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int main()
  5. {
  6. char arr[] = "WORLD";
  7. cout << "Enter a letter to search for\n";
  8.  
  9. char c;
  10. cin >> c;
  11.  
  12. char* beg = arr;
  13. char* end = arr + sizeof arr;
  14. char* pos = find(beg, end, c);
  15. int cnt = count(beg, end, c);
  16.  
  17. if(pos == end)
  18. cout << "Not found\n";
  19. else
  20. cout << "The letter " << c << " found " << cnt << " times. "
  21. << "The first time at position " << 1 + pos - beg << '\n';}
Success #stdin #stdout 0.01s 2684KB
stdin
R
stdout
Enter a letter to search for
The letter R found 1 times. The first time at position 3