fork download
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <sstream>
  6. using namespace std;
  7.  
  8. //removes punctuation, numbers, and extra spaces
  9. void removeNonAlph(string &tmp)
  10. {
  11. for(int i = 0; i < tmp.length(); i++)
  12. {
  13. if (ispunct(tmp[i]))
  14. tmp.erase(i--, 1);
  15. else if (isdigit(tmp[i]))
  16. tmp.erase(i--, 1);
  17. else if ((tmp[i] == ' ') && (tmp[i+1]) == ' ')
  18. tmp.erase(i--, 1);
  19. }
  20. }
  21.  
  22. int main(int argc, const char * argv[])
  23. {
  24.  
  25. //ifstream file("2.txt");
  26. istream& file = cin;
  27. string tmp;
  28. string words[500];
  29.  
  30. while (getline(file, tmp))
  31. {
  32. removeNonAlph(tmp);
  33. // tolower(tmp);
  34. cout << tmp << endl;
  35. }
  36.  
  37. // file.close();
  38. }
Success #stdin #stdout 0s 15240KB
stdin
How are you?

I'm fine, thanks.
stdout
How are you

Im fine thanks