fork(1) download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9. stringstream myfile{"hello124\t4\nzxA23\n2\nz"};
  10.  
  11. if (myfile) { //if file is open then
  12. int c;
  13. while((c = myfile.get())!=EOF){ //while succesful read
  14. //remove all chars, special and whitespace
  15. if (isdigit(c) || c=='\n')
  16. cout.put(c); // then write the line in the output file
  17. }
  18. }
  19. else{
  20. cout << "Error in opening file" << endl;
  21. }
  22. return 0;
  23. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1244
23
2