DilyaraL

Лаба8

Mar 28th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <fstream>
  3. #include <iostream>//
  4. using namespace std;//
  5.  
  6. int main()
  7. {
  8. ifstream f1("Text.txt");//отсюда читаем
  9. /*
  10. ifstream f1; //то же самое, что и наверху
  11. f1.open("Text.txt");
  12. */
  13. ofstream f2("Text1.txt");//сюда записываем количество слов
  14. ofstream f3("Text2.txt");//записываем сам текст
  15. char x, pre;
  16. int count=0;
  17. if (f1.get(x))//для первого символа
  18. {
  19. f3 << x;
  20. if (x != ' ')
  21. count++;
  22. pre = x;
  23. }
  24. while (f1.get(x))//пока файл не кончился считываем один символ
  25. {
  26. f3 << x;//записываем в 3 файл
  27. if (pre == ' '&&x != ' ')
  28. count++;
  29. pre = x;
  30. }
  31. f2 << count;
  32. f1.close();
  33. f2.close();
  34. f3.close();
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment