Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string>
- #include <iostream>
- #include <Windows.h>
- #include <conio.h>
- #include <fstream>
- using namespace std;
- string buff;
- typedef string* Text[100];
- int n;
- ifstream fin;
- ofstream fout;
- short menu();
- void vvod();
- void list();
- void out(Text& X, bool& l, int &length);
- void deleteStr(Text &X, int &length);
- void clearFile();
- int main() {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- Text X;
- int length = 0;
- short choise;
- bool k = true;
- do {
- choise = menu();
- switch (choise) {
- case 1:
- system("cls");
- vvod();
- system("pause");
- system("cls");
- break;
- case 2:
- system("cls");
- list();
- system("pause");
- system("cls");
- break;
- case 3:
- system("cls");
- out(X, k, length);
- system("pause");
- system("cls");
- break;
- case 4:
- if (k) {
- system("cls");
- cout << "Текст не был разделён на строчки! Для начала выполните соответствующую функцию." << endl;
- system("pause");
- system("cls");
- break;
- }
- system("cls");
- int i, j;
- cout << "Кол-во строк: " << n << endl;
- deleteStr(X, length);
- system("pause");
- system("cls");
- break;
- case 5:
- system("cls");
- clearFile();
- system("pause");
- system("cls");
- break;
- case 0:
- cout << "До свидания!!!" << endl;
- system("pause");
- break;
- default:
- cout << "Неверный выбор!!!" << endl;
- cout << "\n\nPress Enter..." << endl;
- system("pause");
- system("cls");
- break;
- }
- } while (choise);
- cout << endl;
- return 0;
- }
- short menu() {
- short v;
- cout << " МЕНЮ" << endl;
- cout << " Введите [1] для ввода текста\n";
- cout << " Введите [2] для просмотра текста\n";
- cout << " Введите [3] для разделения текста на строчки\n";
- cout << " Введите [4] для удаления i-ой строки из текста\n";
- cout << " Введите [5] для очистки файла\n";
- cout << " Введите [0] для выхода\n";
- cout << " Пункт: ";
- cin >> v;
- return v;
- }
- void vvod() {
- fout.open("Text.txt", ios_base::app);
- system("cls");
- getline(cin, buff);
- string s;
- cout << "Введите строку: ";
- getline(cin, s);
- fout << s;
- fout.close();
- cout << "Текст введен в файл: " << endl;
- cout << s << endl;
- }
- void list() {
- ifstream fin("Text.txt");
- if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
- else {
- string text;
- getline(fin, text);
- cout << text << endl;
- fin.close();
- }
- }
- void out(Text &X, bool& l, int &length) {
- system("cls");
- ifstream fin("Text.txt");
- if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
- else {
- cout << "Введите длину строки: ";
- cin >> length;
- string text;
- int c = 0;
- int i = 0;
- getline(fin, text);
- while (c < text.length()) {
- string TX = text.substr(c, length);
- c += length;
- X[i] = new string;
- *X[i] = TX;
- i++;
- }
- for (int g = 0; g < i; g++) {
- for (int j = 0; j < i; j++) {
- l = false;
- n = i;
- g++;
- cout << g << ". " << *X[j] << endl;
- }
- }
- cout << "Кол-во строк: " << n << endl;
- cout << "Запомните номер строки, которую вы вдруг захотите удалить и длину всех строк.\n";
- fin.close();
- }
- }
- void deleteStr(Text &X, int &length) {
- ofstream fout("updated_Text.txt");
- ifstream fin("Text.txt");
- if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
- else {
- string text;
- int c = 0, m = 0;
- getline(fin, text);
- cout << "Изначальный текст:" << endl;
- while (c < text.length()) {
- cout << m << ". " << text.substr(c, length) << endl;
- c += length;
- m += 1;
- }
- int ind;
- cout << "Введите индекс строки, которую хотите удалить(считать с нуля):" << endl;
- cin >> ind;
- if (ind+1 > m) {
- cout << "Введен неверный индекс строки!" << endl;
- return;
- }
- else {
- for (int i = 0; i < m-1; i++) {
- if (ind == i) {
- swap(X[i], X[i+1]);
- ind++;
- }
- }
- delete X[ind];
- }
- cout << endl << "Измененный текст:" << endl;
- for (int k = 0; k < m - 1; k++) {
- cout << *X[k] << endl;
- fout << *X[k];
- }
- fin.close();
- fout.close();
- remove("Text.txt");
- rename("updated_Text.txt", "Text.txt");
- }
- }
- void clearFile() { //очистка файла
- cout << "Файл успешно очищен! \n";
- ofstream fclear("Text.txt", ios_base::trunc);
- fclear.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement