fork download
  1. #include <fstream>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cctype>
  5. using namespace std;
  6. int main()
  7. {
  8. // using std::cin for this demo
  9. // ifstream in_data("test.txt");
  10. // if (!in_data)
  11. // {
  12. // cout << "Input file opening failed.\n";
  13. // return 1;
  14. // }
  15. char next_symbol;
  16. int count = 0;
  17. while( /*in_data*/ cin.get(next_symbol) )
  18. {
  19. if (islower(next_symbol))
  20. {
  21. next_symbol = toupper(next_symbol);
  22. }
  23. if (next_symbol == ' ')
  24. {
  25. count++;
  26. }
  27. else
  28. {
  29. if (count>0)
  30. {
  31. cout << " ";
  32. }
  33. count=0;
  34. cout << next_symbol;
  35. }
  36. }
  37. cout << endl;
  38. }
Success #stdin #stdout 0s 2728KB
stdin
This is a file       with     many.....  spaces!


and      several newlines,

too.
stdout
THIS IS A FILE WITH MANY..... SPACES!


AND SEVERAL NEWLINES,

TOO.