Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include <iostream>
  2. #include<string>
  3. #include<fstream>
  4. #include<ctime>
  5. #include<Windows.h>
  6. using namespace std;
  7. int main()
  8. {
  9.     setlocale(LC_ALL, "rus");
  10.     SetConsoleCP(1251);
  11.     SetConsoleOutputCP(1251);
  12.     srand(time(0));
  13.     const int size = 10;
  14.     int  array[size], array_g[size];
  15.     string str;
  16.     ofstream fout, gout;
  17.     string filename = "task7.txt";
  18.     string filename1 = "task7varg.txt";
  19.     fout.open(filename);
  20.     gout.open(filename1);
  21.     if (!fout.is_open())
  22.     {
  23.         cout << "Ошибка открытия файла" << filename << endl;
  24.     }
  25.     else
  26.     {
  27.         cout << "Файл успешно открылся" << endl;
  28.         cout << "Исходный массив\n";
  29.         for (int i = 0; i < size; i++)
  30.         {
  31.             array[i] = rand() % 30 - 10;
  32.             fout << array[i] << " ";
  33.         }
  34.     }
  35.     fout.close();
  36.     if (!gout.is_open())
  37.     {
  38.         cout << "Ошибка открытия файла " << filename << endl;
  39.     }
  40.     else
  41.     {
  42.         cout << "Дополнительный Файл успешно открылся " << endl;
  43.         gout << "Дополнение массива:\n";
  44.         cout << "Добавление новых позиций: введите число позиций!\n";
  45.         int size2;
  46.         cin >> size2;
  47.         while (size2 < 0)
  48.         {
  49.             cout << "Недопустимое значение позиций!\n";
  50.         }
  51.  
  52.         for (int i = 0; i < size2; i++)
  53.         {
  54.             cin >> array_g[i];
  55.             gout << array_g[i] << " ";
  56.         }
  57.     }
  58.           ifstream fin;
  59.     fin.open(filename);
  60.     if (!fin.is_open())
  61.     {
  62.         cout << "Неудалось открыть и считать файл" << endl;;
  63.     }
  64.     else
  65.     {
  66.         cout << "Файл успешно считался!" << endl;
  67.         while (!fin.eof())
  68.         {
  69.             str = "";
  70.             getline(fin, str);
  71.             gout << str << endl;
  72.         }
  73.     }
  74.     fin.close();
  75.    
  76.     gout.close();
  77.     ifstream gin;
  78.     gin.open(filename1);
  79.     if (!gin.is_open())
  80.     {
  81.         cout << "Неудалось открыть и считать файл" << endl;;
  82.     }
  83.     else
  84.     {
  85.         cout << "Файл успешно считался!" << endl;
  86.         while (!gin.eof())
  87.         {
  88.             str = "";
  89.             getline(gin, str);
  90.             cout << str << endl;
  91.         }
  92.     }
  93.     gin.close();
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement