Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <ctime>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     srand(time(NULL));
  9.     setlocale(0, "");
  10.     ifstream file;
  11.     fstream file2;
  12.     file.open("E:file5.txt");
  13.     file2.open("E:file52.txt", fstream::out | fstream::in);
  14.     if (file.is_open() && file2.is_open()) {
  15.         cout << "Файлы открыты!\n";
  16.         int temp;
  17.         bool key = false;
  18.         cout << "Содержимое файла:\n";
  19.         while (!file.eof()) {
  20.             file >> temp;
  21.             cout << temp << "   ";
  22.             if (temp > 0) {
  23.                 file2 << temp<<"   ";
  24.                 key = true;
  25.             }
  26.         }
  27.         file2.clear();
  28.         file2.seekg(0);
  29.         if (key == true) {
  30.             cout << "\nСодержимое нового файла:\n";
  31.             while (!file2.eof()) {
  32.                 file2 >> temp;
  33.                 cout << temp << "  ";
  34.             }
  35.         }
  36.         else
  37.             cout << "\nВ исходном файле не нашлось положительных чисел!\n";
  38.  
  39.     }
  40.     else
  41.         cout << "Не удалось открыть файлы!\n";
  42.     file.close();
  43.     file2.close();
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement