fork(1) download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. vector<int> randomIntegers{1,2,2,2,3,3,4,4};
  8.  
  9. int searchNumber;
  10. cout << "Enter a search number: ";
  11. cin >> searchNumber;
  12. bool found = find(randomIntegers.begin(), randomIntegers.end(),searchNumber) != randomIntegers.end();
  13.  
  14. if(found)
  15. {
  16. cout << searchNumber << " is in the vector!"<<endl;
  17. int ans = count(randomIntegers.begin(), randomIntegers.end(),searchNumber) ;
  18.  
  19. cout<< "It was found "<< ans<< " times\n";
  20. }
  21. else
  22. cout << searchNumber << " is NOT in the vector!";
  23. return 0;
  24.  
  25.  
  26. }
Success #stdin #stdout 0s 3472KB
stdin
2
stdout
Enter a search number: 2 is in the vector!
It was found 3 times