Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <vector>
- #include <windows.h>
- #undef max()
- using namespace std;
- HANDLE hStdOut;
- void input(vector<wstring>&);
- void find(vector<wstring>&);
- void copy(vector<wstring>&);
- void del(vector<wstring>&);
- void printText(vector<wstring>&);
- int main()
- {
- hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- wcin.imbue(locale("rus_rus.866"));
- wcout.imbue(locale("rus_rus.866"));
- vector<wstring> text;
- wstring buf;
- wcout << L"Введите строку:\n";
- getline(wcin, buf);
- text.emplace_back(buf);
- wcout << endl;
- for (;;)
- {
- int menu = 0;
- wcout << L"Выберите пункт меню:\n"
- L"1: Ввести следующую строку\n"
- L"2: Поиск символа (ов)\n"
- L"3: Копирование строк\n"
- L"4: Удаление символов с конца строки\n"
- L"5: Выход\n";
- wcin >> menu;
- switch (menu)
- {
- case 1:
- input(text);
- break;
- case 2:
- find(text);
- break;
- case 3:
- copy(text);
- break;
- case 4:
- del(text);
- break;
- case 5:
- return 0;
- default:
- wcout << L"Попробуйте снова\n";
- wcin.clear();
- wcin.ignore(numeric_limits<streamsize>::max(), '\n');
- continue;
- }
- }
- }
- void input(vector<wstring>& t)
- {
- wstring buf;
- wcout << L"Введите строку:\n";
- wcin.clear();
- wcin.ignore(numeric_limits<streamsize>::max(), '\n');
- getline(wcin, buf);
- t.emplace_back(buf);
- printText(t);
- }
- void find(vector<wstring>& t)
- {
- size_t count = 0;
- wstring str;
- wcout << L"Искать:\n";
- wcin >> str;
- for (wstring line : t)
- {
- for (int pos = 0, lastPos = 0; pos < line.length(); pos++)
- {
- lastPos = pos;
- pos = line.find(str, pos);
- wcout << line.substr(lastPos, pos - lastPos);
- if (pos != wstring::npos)
- {
- SetConsoleTextAttribute(hStdOut, FOREGROUND_GREEN);
- wcout << line.substr(pos, str.length());
- count++;
- }
- //else
- // SetConsoleTextAttribute(hStdOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
- SetConsoleTextAttribute(hStdOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
- }
- wcout << endl;
- }
- wcout << L"Найдено " << count << endl;
- }
- void copy(vector<wstring>& t)
- {
- m1: size_t from = t.size() + 1;
- size_t to = from + 1;
- wcout << L"Из строки №";
- wcin >> from;
- wcout << L"В строку №";
- wcin >> to;
- from--;
- to--;
- if (from > t.size() - 1 || to > t.size())
- {
- wcout << L"Попробуйте снова\n";
- wcin.clear();
- wcin.ignore(numeric_limits<streamsize>::max(), '\n');
- goto m1;
- }
- t.insert(t.cbegin() + to, t[from]);
- printText(t);
- }
- void del(vector<wstring>& t)
- {
- m2: size_t line = t.size() + 1;
- wcout << L"Из строки №";
- wcin >> line;
- size_t num = t[line].length() + 1;
- wcout << L"Количество символов: ";
- wcin >> num;
- line--;
- if (line > t.size() - 1 || num > t[line].length())
- {
- wcout << L"Попробуйте снова\n";
- wcin.clear();
- wcin.ignore(numeric_limits<streamsize>::max(), '\n');
- goto m2;
- }
- t[line].erase(t[line].length() - num, num);
- printText(t);
- }
- void printText(vector<wstring>&t)
- {
- wcout << L"\nТекст:\n";
- for (wstring s : t)
- wcout << s << endl;
- wcout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement