kolioi

21. Filter Strings C++

Dec 2nd, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. std::string FilterString(const std::string&);
  5.  
  6. int main()
  7. {
  8.  
  9.     std::string s;
  10.     std::cin >> s;
  11.  
  12.     std::cout << FilterString(s) << std::endl;
  13.  
  14.     return 0;
  15. }
  16.  
  17. std::string FilterString(const std::string& s)
  18. {
  19.     std::string out;
  20.     for (char ch : s)
  21.         if ('0' <= ch && ch <= '9')
  22.             out += ch;
  23.  
  24.     return out;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment