fork(3) download
  1. #include <fstream>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <iostream>
  5. bool two_spaces(char c1, char c2)
  6. {
  7. return c1 == ' ' && c2 == ' ';
  8. }
  9. int main()
  10. {
  11. // using std::cin for this demo
  12. // std::ifstream in_data("test.txt");
  13. std::istreambuf_iterator<char> beg(/*in_data*/ std::cin), end;
  14. std::string str;
  15. std::transform(beg, end, back_inserter(str), ::toupper);
  16. std::unique_copy(str.begin(), str.end(),
  17. std::ostreambuf_iterator<char>(std::cout),
  18. two_spaces);
  19. }
  20.  
Success #stdin #stdout 0s 2860KB
stdin
This is a file       with     many.....  spaces!


and      several newlines,

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


AND SEVERAL NEWLINES,

TOO.