Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <sstream>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. void toFile(fstream &f, string buff) //Функция записи в файл
  11. {
  12. f.open("word.txt");
  13. if (f.fail())
  14. {
  15. cout << "\n Ошибка открытия файла";
  16. exit(1);
  17. }
  18. f << buff;
  19. f.close();
  20. }
  21.  
  22. void FindWord(string s1, string s2, string &word)
  23. {
  24. int szmax = 0, sz;
  25. istringstream iss(s1);
  26. string t;
  27. while (iss >> t)
  28. {
  29. sz = t.length();
  30. if (sz > szmax)
  31. {
  32. word = t;
  33. szmax = sz;
  34. }
  35. }
  36. }
  37.  
  38.  
  39. int main()
  40. {
  41.  
  42. setlocale(0, "");
  43. string s1, s2, word;
  44. fstream f;
  45.  
  46. cout << "Введите предложение 1:" << endl;
  47. cin.ignore();
  48. getline(cin, s1);
  49. cout << "Введите предложение 2:" << endl;
  50. cin.ignore();
  51. getline(cin, s2);
  52. FindWord(s1, s2, word);
  53.  
  54. cout << "Искомое слово" << word << endl; //вывод на экран
  55. toFile(f, word); //вывод в файл
  56.  
  57. //cgetch();// system("pause");
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement