Advertisement
35657

Untitled

Dec 1st, 2023
662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <Windows.h>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     SetConsoleCP(1251);
  9.     SetConsoleOutputCP(1251);
  10.  
  11.     ifstream fin;
  12.     fin.open("C:/Users/PC/Desktop/file.txt");
  13.  
  14.     if (!fin.is_open()) {
  15.         cout << "Ошибка открытия файла" << endl;
  16.     }
  17.     else {
  18.         int size = 0;
  19.         string word, longest_word;
  20.  
  21.         while (!fin.eof()) {
  22.             fin >> word;
  23.             if (word.size() > size) {
  24.                 longest_word = word;
  25.                 size = word.size();
  26.             }
  27.         }
  28.         fin.close();
  29.         cout << longest_word << endl;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement