fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template<typename T>
  6. vector<T> filter(vector<T> base, T val) {
  7. vector<T> temp;
  8. for (auto it : base) if (it == val) temp.push_back(it);
  9. return temp;
  10. }
  11.  
  12. int main() {
  13. vector<int> v = {7, 5, 16, 8, 5, 12, 1};
  14. for (auto it : filter(v, 5)) cout << it << endl;
  15. }
  16.  
  17. //https://pt.stackoverflow.com/q/215352/101
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
5
5