Advertisement
Guest User

паст EBIN :----d

a guest
May 27th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <fstream>
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using namespace std;
  8. int CountWords(string name);
  9. int CountLines(string name);
  10. int main()
  11. {
  12.     setlocale(LC_ALL, "Russian");
  13.     string fileText;
  14.     string fileName = "Temp.txt";
  15.     int symbCount = 0, wordCount = 0, stringCount = 0, paragraphCount = 0;
  16.     ifstream fileWithText(fileName);
  17.     if (!fileWithText.is_open()) {
  18.         cout << "File cannot be opened" << endl;
  19.         getchar();
  20.         return 0;
  21.     }
  22.     cout << "File is opened" << endl;
  23.     fileWithText.close();
  24.    
  25.     cout << "Количество слов: " << CountWords(fileName) << endl;
  26.     cout << "Количество строк: " << CountLines(fileName) << endl;
  27.     getchar();
  28.    
  29.     system("pause");
  30.  
  31.     return 0;
  32. }
  33. int CountLines(string name) {
  34.     ifstream file(name);
  35.     string temp;
  36.     int count = 0;
  37.     while (!file.eof()) {
  38.         getline(file, temp);
  39.         if (temp[0] == '    ')
  40.             cout << "АБЗАЦ ЕСТЬ " << endl;
  41.         count++;
  42.     }
  43.     return count;
  44. }
  45. int CountWords(string name) {
  46.     ifstream file(name);
  47.     string temp;
  48.     int count = 0;
  49.     cout << "text: " << endl;
  50.     while (!file.eof()) {
  51.        
  52.         file >> temp;
  53.        
  54.         count++;
  55.     }
  56.     return count;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement