Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <filesystem>
- #include <sstream>
- using namespace std;
- string getFilePath()
- {
- string path;
- bool isIncorrect;
- do
- {
- cout << "Введите абсолютный путь к файлу: " << endl;
- cin >> path;
- isIncorrect = false;
- if (!std::filesystem::exists(path))
- {
- cout << "Файл не найден. Проверьте введённый путь." << endl;
- isIncorrect = true;
- }
- } while (isIncorrect);
- return path;
- }
- string fileToSentence(string& sentence, string path)
- {
- fstream SenFile(path, fstream::in);
- getline(SenFile, sentence);
- cout << endl;
- return sentence;
- }
- void printSentenceBO(string sentence)
- {
- cout << "Исходное предложение: " << endl;
- cout << sentence << endl;
- cout << endl;
- }
- string getCondition(string sentence)
- {
- while (sentence[0] == ' '){
- sentence.erase(0, 1);
- }
- int pos;
- while ((pos = sentence.find(" ")) > 0) {
- sentence.erase(pos, 1);
- }
- while (sentence.back() == ' ') {
- sentence.erase(sentence.back(), 1);
- }
- return sentence;
- }
- void printSentencePO(string sentence)
- {
- cout << "Исправленное предложение:" << endl;
- cout << sentence << endl;
- }
- string getOutput()
- {
- string patho;
- bool isIncorrect;
- isIncorrect = true;
- do
- {
- cout << "Введите директорию, в которую хотите сохранить ответ:" << endl;
- cin >> patho;
- if (filesystem::exists(patho))
- {
- isIncorrect = false;
- }
- else
- {
- cout << "Такой директории не существует. Попробуйте ещё раз." << endl;
- }
- } while (isIncorrect);
- return patho;
- }
- void getConditionToFile(string sentence)
- {
- string path;
- path = getOutput();
- ofstream fout;
- fout.open(path + "\output.txt");
- fout << sentence << endl;
- fout.close();
- cout << "Результат сохранён по указанному пути.";
- }
- int main()
- {
- setlocale(LC_ALL, "ru");
- string sentence;
- string path;
- path = getFilePath();
- sentence = fileToSentence(sentence, path);
- printSentenceBO(sentence);
- sentence = getCondition(sentence);
- printSentencePO(sentence);
- getConditionToFile(sentence);
- }
Advertisement
Add Comment
Please, Sign In to add comment