Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<string>
- #include<fstream>
- #include<ctime>
- #include<Windows.h>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "rus");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- srand(time(0));
- const int size = 10;
- int array[size], array_g[size];
- string str;
- ofstream fout, gout;
- string filename = "task7.txt";
- string filename1 = "task7varg.txt";
- fout.open(filename);
- gout.open(filename1);
- if (!fout.is_open())
- {
- cout << "Ошибка открытия файла" << filename << endl;
- }
- else
- {
- cout << "Файл успешно открылся" << endl;
- cout << "Исходный массив\n";
- for (int i = 0; i < size; i++)
- {
- array[i] = rand() % 30 - 10;
- fout << array[i] << " ";
- }
- }
- fout.close();
- if (!gout.is_open())
- {
- cout << "Ошибка открытия файла " << filename << endl;
- }
- else
- {
- cout << "Дополнительный Файл успешно открылся " << endl;
- gout << "Дополнение массива:\n";
- cout << "Добавление новых позиций: введите число позиций!\n";
- int size2;
- cin >> size2;
- while (size2 < 0)
- {
- cout << "Недопустимое значение позиций!\n";
- }
- for (int i = 0; i < size2; i++)
- {
- cin >> array_g[i];
- gout << array_g[i] << " ";
- }
- }
- ifstream fin;
- fin.open(filename);
- if (!fin.is_open())
- {
- cout << "Неудалось открыть и считать файл" << endl;;
- }
- else
- {
- cout << "Файл успешно считался!" << endl;
- while (!fin.eof())
- {
- str = "";
- getline(fin, str);
- gout << str << endl;
- }
- }
- fin.close();
- gout.close();
- ifstream gin;
- gin.open(filename1);
- if (!gin.is_open())
- {
- cout << "Неудалось открыть и считать файл" << endl;;
- }
- else
- {
- cout << "Файл успешно считался!" << endl;
- while (!gin.eof())
- {
- str = "";
- getline(gin, str);
- cout << str << endl;
- }
- }
- gin.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement