Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <vector>
- std::wstring ReadLine();
- void CopyLine(std::vector<std::wstring>& text);
- void DeleteChars(std::vector<std::wstring>& text);
- void Print(std::vector<std::wstring>& text);
- int main()
- {
- std::wcin.imbue(std::locale("rus_rus.866"));
- std::wcout.imbue(std::locale("rus_rus.866"));
- std::vector<std::wstring> text;
- unsigned menu;
- for (;;)
- {
- std::wcout << L"\nЧто Вы хотите сделать?" << std::endl;
- std::wcout << L"1 - ввести новую строку и добавить в конец текста" << std::endl;
- std::wcout << L"2 - ввести новую строку и добавить в начало текста" << std::endl;
- std::wcout << L"3 - скопировать строку" << std::endl;
- std::wcout << L"4 - удалить символы с начала строки" << std::endl;
- std::wcout << L"5 - выйти\n" << std::endl;
- if (!(std::wcin >> menu))
- {
- std::wcin.clear();
- std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
- std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
- continue;
- }
- switch (menu)
- {
- case 1:
- text.push_back(ReadLine());
- break;
- case 2:
- text.insert(text.begin(), ReadLine());
- break;
- case 3:
- CopyLine(text);
- break;
- case 4:
- DeleteChars(text);
- break;
- case 5:
- system("pause");
- return 0;
- default:
- std::wcout << L"Ошибка! Не найден такой пункт в меню" << std::endl;
- }
- Print(text);
- }
- }
- void CopyLine(std::vector<std::wstring>& text)
- {
- if (text.empty())
- {
- std::wcout << L"Ошибка! Текст пуст" << std::endl;
- return;
- }
- unsigned fromLine, beforeLine;
- for (;;)
- {
- std::wcout << L"\nВведите номер копируемой строки: ";
- if (!(std::wcin >> fromLine) || fromLine > text.size() || fromLine < 1)
- {
- std::wcin.clear();
- std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
- std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
- continue;
- }
- std::wcout << L"Введите номер, куда будет скопирована строка: ";
- if (!(std::wcin >> beforeLine) || beforeLine > text.size() || beforeLine < 1)
- {
- std::wcin.clear();
- std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
- std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
- continue;
- }
- break;
- }
- text.insert(text.begin() + beforeLine - 1, *(text.begin() + fromLine - 1));
- }
- void Print(std::vector<std::wstring>& text)
- {
- if (text.empty())
- {
- return;
- }
- std::wcout << std::endl;
- std::wcout << L"Текст:" << std::endl;
- for (const auto& line : text)
- std::wcout << line << std::endl;
- }
- void DeleteChars(std::vector<std::wstring>& text)
- {
- if (text.empty())
- {
- std::wcout << L"Ошибка! Текст пуст" << std::endl;
- return;
- }
- unsigned line, quantity;
- for (;;)
- {
- std::wcout << L"\nВведите номер строки: ";
- if (!(std::wcin >> line) || line < 1 || line > text.size())
- {
- std::wcin.clear();
- std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
- std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
- continue;
- }
- std::wcout << L"Введите количество символов: ";
- if (!(std::wcin >> quantity) || quantity > text[line].size() || quantity < 1)
- {
- std::wcin.clear();
- std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
- std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
- continue;
- }
- break;
- }
- text[line - 1].erase(text[line - 1].begin(), text[line - 1].begin() + quantity);
- }
- std::wstring ReadLine()
- {
- std::wstring buffer;
- std::wcout << L"\nВведите строку:" << std::endl;
- std::wcin.clear();
- std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
- std::getline(std::wcin, buffer);
- return buffer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement