Advertisement
intsas

Untitled

Jul 15th, 2020
1,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     setlocale(0, "");
  9.  
  10.     string nameInputFile;
  11.     cout << "Введите имя входного файла: ";
  12.     cin >> nameInputFile;
  13.     ifstream inputFile(nameInputFile.c_str());
  14.     if (!inputFile.is_open()) {
  15.         cout << "Не удалось открыть входной файл" << endl;
  16.         return 0;
  17.     }
  18.  
  19.     string nameOutputFile;
  20.     cout << "Введите имя выходного файла: ";
  21.     cin >> nameOutputFile;
  22.     ofstream outputFile(nameOutputFile.c_str());
  23.     if (!outputFile.is_open()) {
  24.         cout << "Не удалось открыть выходной файл" << endl;
  25.         return 0;
  26.     }
  27.  
  28.     string abc;
  29.     while (!inputFile.eof()) {
  30.         inputFile >> abc;
  31.         if (abc[0] == abc[abc.length() - 1]) {
  32.             outputFile << abc << endl;
  33.             cout << abc << endl;
  34.         }
  35.     }
  36.  
  37.     inputFile.close();
  38.     outputFile.close();
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement