Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- using namespace std;
- void toFile(fstream &f, string buff) //Функция записи в файл
- {
- f.open("word.txt");
- if (f.fail())
- {
- cout << "\n Ошибка открытия файла";
- exit(1);
- }
- f << buff;
- f.close();
- }
- void FindWord(string s1, string s2, string &word)
- {
- int szmax = 0, sz;
- istringstream iss(s1);
- string t;
- while (iss >> t)
- {
- sz = t.length();
- if (sz > szmax)
- {
- word = t;
- szmax = sz;
- }
- }
- }
- int main()
- {
- setlocale(0, "");
- string s1, s2, word;
- fstream f;
- cout << "Введите предложение 1:" << endl;
- cin.ignore();
- getline(cin, s1);
- cout << "Введите предложение 2:" << endl;
- cin.ignore();
- getline(cin, s2);
- FindWord(s1, s2, word);
- cout << "Искомое слово" << word << endl; //вывод на экран
- toFile(f, word); //вывод в файл
- //cgetch();// system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement