MaksNew

Untitled

Nov 5th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <filesystem>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. string getFilePath()
  10. {
  11.     string path;
  12.     bool isIncorrect;
  13.     do
  14.     {
  15.         cout << "Введите абсолютный путь к файлу: " << endl;
  16.         cin >> path;
  17.         isIncorrect = false;
  18.         if (!std::filesystem::exists(path))
  19.         {
  20.             cout << "Файл не найден. Проверьте введённый путь." << endl;
  21.             isIncorrect = true;
  22.         }
  23.     } while (isIncorrect);
  24.     return path;
  25. }
  26.  
  27.  
  28. string fileToSentence(string& sentence, string path)
  29. {
  30.     fstream SenFile(path, fstream::in);
  31.     getline(SenFile, sentence);
  32.     cout << endl;
  33.     return sentence;
  34. }
  35.  
  36. void printSentenceBO(string sentence)
  37. {
  38.     cout << "Исходное предложение: " << endl;
  39.     cout << sentence << endl;
  40.     cout << endl;
  41. }
  42.  
  43. string getCondition(string sentence)
  44. {
  45.     while (sentence[0] == ' '){
  46.         sentence.erase(0, 1);
  47.     }
  48.     while ((sentence.find("  ")) > 0) {
  49.         sentence.erase(sentence.find("  "), 1);
  50.     }
  51.     while (sentence.back() == ' ') {
  52.         sentence.erase(sentence.back(), 1);
  53.     }
  54.     return sentence;
  55. }
  56.  
  57. void printSentencePO(string sentence)
  58. {
  59.     cout << "Исправленное предложение:" << endl;
  60.     cout << sentence << endl;
  61. }
  62.  
  63. string getOutput()
  64. {
  65.     string patho;
  66.     bool isIncorrect;
  67.     isIncorrect = true;
  68.     do
  69.     {
  70.         cout << "Введите директорию, в которую хотите сохранить ответ:" << endl;
  71.         cin >> patho;
  72.         if (filesystem::exists(patho))
  73.         {
  74.             isIncorrect = false;
  75.         }
  76.         else
  77.         {
  78.             cout << "Такой директории не существует. Попробуйте ещё раз." << endl;
  79.         }
  80.  
  81.     } while (isIncorrect);
  82.     return patho;
  83. }
  84.  
  85. void getConditionToFile(string sentence)
  86. {
  87.     string path;
  88.     path = getOutput();
  89.     ofstream fout;
  90.     fout.open(path + "\output.txt");
  91.     fout << sentence << endl;
  92.     fout.close();
  93.     cout << "Результат сохранён по указанному пути.";
  94.  
  95. }
  96.  
  97.  
  98. int main()
  99. {
  100.     setlocale(LC_ALL, "ru");
  101.     string sentence;
  102.     string path;
  103.     path = getFilePath();
  104.     sentence = fileToSentence(sentence, path);
  105.     printSentenceBO(sentence);
  106.     sentence = getCondition(sentence);
  107.     printSentencePO(sentence);
  108.     getConditionToFile(sentence);
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment