View difference between Paste ID: CcLCStVn and Qa90MVTH
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h>
2
#include <string>
3
#include <iostream>
4
#include <Windows.h>
5
#include <conio.h>
6
#include <fstream>
7
8
using namespace std;
9
string buff;
10
typedef string* Text[100];
11
int n;
12
13
ifstream fin;
14
ofstream fout;
15
16
short menu();
17
void vvod();
18
void list();
19-
void out(Text X, bool& l);
19+
void out(Text& X, bool& l, int &length);
20-
void deleteStr(Text X, int i);
20+
void deleteStr(Text &X, int &length);
21
void clearFile();
22
23
int main() {
24
    SetConsoleCP(1251);
25-
    SetConsoleOutputCP(1251); 
25+
    SetConsoleOutputCP(1251);
26
    Text X;
27
    int length = 0;
28
    short choise;
29
    bool k = true;
30
    do {
31
        choise = menu();
32
        switch (choise) {
33
        case 1:
34
            system("cls");
35
            vvod();
36
            system("pause");
37
            system("cls");
38
            break;
39
        case 2:
40
            system("cls");
41
            list();
42
            system("pause");
43
            system("cls");
44
            break;
45
        case 3:
46-
            out(X, k);
46+
47
            out(X, k, length);
48
            system("pause");
49
            system("cls");
50
            break;
51
        case 4:
52
            if (k) {
53
                system("cls");
54
                cout << "Текст не был разделён на строчки! Для начала выполните соответствующую функцию." << endl;
55
                system("pause");
56
                system("cls");
57
                break;
58
            }
59
            system("cls");
60
            int i, j;
61-
            cout << "Введите индекс строки, которую хотите удалить(считать с нуля):" << endl;
61+
62-
            cin >> i;
62+
            
63-
            deleteStr(X, i);
63+
            deleteStr(X, length);
64
            system("pause");
65
            system("cls");
66
            break;
67
        case 5:
68
            system("cls");
69
            clearFile();
70
            system("pause");
71
            system("cls");
72
            break;
73
        case 0:
74
            cout << "До свидания!!!" << endl;
75
            system("pause");
76
            break;
77
        default:
78
            cout << "Неверный выбор!!!" << endl;
79
            cout << "\n\nPress Enter..." << endl;
80
            system("pause");
81
            system("cls");
82
            break;
83
        }
84
    } while (choise);
85
    cout << endl;
86
    return 0;
87-
} 
87+
88
89
short menu() {
90
    short v;
91
    cout << "           МЕНЮ" << endl;
92
    cout << " Введите [1] для ввода текста\n";
93
    cout << " Введите [2] для просмотра текста\n";
94
    cout << " Введите [3] для разделения текста на строчки\n";
95
    cout << " Введите [4] для удаления i-ой строки из текста\n";
96
    cout << " Введите [5] для очистки файла\n";
97
    cout << " Введите [0] для выхода\n";
98
    cout << " Пункт: ";
99
    cin >> v;
100
    return v;
101
}
102
103
void vvod() {
104
    fout.open("Text.txt", ios_base::app);
105
    system("cls");
106
    getline(cin, buff);
107
    string s;
108
    cout << "Введите строку: ";
109
    getline(cin, s);
110
    fout << s;
111
    fout.close();
112
    cout << "Текст введен в файл: " << endl;
113
    cout << s << endl;
114
}
115
116
void list() {
117
    ifstream fin("Text.txt");
118
    if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
119
    else {
120
        string text;
121
        getline(fin, text);
122
        cout << text << endl;
123
        fin.close();
124
    }
125
}
126
127-
void out(Text X, bool& l) {
127+
void out(Text &X, bool& l, int &length) {
128
    system("cls");
129
    ifstream fin("Text.txt");
130
    if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
131
    else {
132-
        int d;
132+
133
        cin >> length;
134-
        cin >> d;
134+
135
        int c = 0;
136
        int i = 0;
137
        getline(fin, text);
138
        while (c < text.length()) {
139
            string TX = text.substr(c, length);
140-
            string TX = text.substr(c, d);
140+
            c += length;
141-
            c += d;
141+
142
            *X[i] = TX;
143
            i++;
144
        }
145
        for (int g = 0; g < i; g++) {
146-
        for (int g = -1; g < i; g++) {
146+
147
                l = false;
148
                n = i;
149
                g++;
150
                cout << g << ". " << *X[j] << endl;
151
            }
152
        }
153
        cout << "Кол-во строк: " << n << endl;
154
        cout << "Запомните номер строки, которую вы вдруг захотите удалить и длину всех строк.\n";
155
        fin.close();
156
    }
157
}
158
159
void deleteStr(Text &X, int &length) {
160-
void deleteStr(Text X, int i) {
160+
    ofstream fout("updated_Text.txt");
161
    ifstream fin("Text.txt");
162
    if (fin.peek() == EOF) cout << "Ваш файл пуст! Введите текст.\n"; // если первый символ конец файла
163
    else {
164
        string text;
165
        int c = 0, m = 0;
166
        getline(fin, text);
167-
        int d;
167+
168-
        cout << "Повторите длину строки: " << endl;
168+
169-
        cin >> d;
169+
            cout << m << ". " << text.substr(c, length) << endl;
170
            c += length;
171
            m += 1;
172-
            cout << text.substr(c, d) << endl;
172+
173-
            c += d;
173+
        int ind;
174
        cout << "Введите индекс строки, которую хотите удалить(считать с нуля):" << endl;
175
        cin >> ind;
176-
        delete(X[i]);
176+
        if (ind+1 > m) {
177
            cout << "Введен неверный индекс строки!" << endl;
178-
        for (int k = 0; k < m; k++) cout << *X[k] << endl;
178+
            return;
179
        }
180
        else {
181
            for (int i = 0; i < m-1; i++) {
182
                if (ind == i) {
183
                    swap(X[i], X[i+1]);
184
                    ind++;
185
                }
186
            }
187
            delete X[ind];
188
        }
189
        cout << endl << "Измененный текст:" << endl;
190
        for (int k = 0; k < m - 1; k++) {
191
            cout << *X[k] << endl;
192
            fout << *X[k];
193
        }
194
        fin.close();
195
        fout.close();
196
197
        remove("Text.txt");
198
        rename("updated_Text.txt", "Text.txt");
199
    }
200
}
201
202
void clearFile() {  //очистка файла
203
    cout << "Файл успешно очищен! \n";
204
    ofstream fclear("Text.txt", ios_base::trunc);
205
    fclear.close();
206
}