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. string line;
  13. while(getline(myfile, line)){ //while succesful read
  14. //remove all chars, special and whitespace
  15. line.erase(remove_if(line.begin(), line.end(), [](const char& c) { return !isdigit(c); } ), line.end());
  16. cout << line<<endl; // 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 3472KB
stdin
Standard input is empty
stdout
1244
23
2