Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <vector>
  5.  
  6. std::wstring ReadLine();
  7. void CopyLine(std::vector<std::wstring>& text);
  8. void DeleteChars(std::vector<std::wstring>& text);
  9. void Print(std::vector<std::wstring>& text);
  10.  
  11. int main()
  12. {
  13. std::wcin.imbue(std::locale("rus_rus.866"));
  14. std::wcout.imbue(std::locale("rus_rus.866"));
  15. std::vector<std::wstring> text;
  16. unsigned menu;
  17. for (;;)
  18. {
  19. std::wcout << L"\nЧто Вы хотите сделать?" << std::endl;
  20. std::wcout << L"1 - ввести новую строку и добавить в конец текста" << std::endl;
  21. std::wcout << L"2 - ввести новую строку и добавить в начало текста" << std::endl;
  22. std::wcout << L"3 - скопировать строку" << std::endl;
  23. std::wcout << L"4 - удалить символы с начала строки" << std::endl;
  24. std::wcout << L"5 - выйти\n" << std::endl;
  25. if (!(std::wcin >> menu))
  26. {
  27. std::wcin.clear();
  28. std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
  29. std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
  30. continue;
  31. }
  32. switch (menu)
  33. {
  34. case 1:
  35. text.push_back(ReadLine());
  36. break;
  37. case 2:
  38. text.insert(text.begin(), ReadLine());
  39. break;
  40. case 3:
  41. CopyLine(text);
  42. break;
  43. case 4:
  44. DeleteChars(text);
  45. break;
  46. case 5:
  47. system("pause");
  48. return 0;
  49. default:
  50. std::wcout << L"Ошибка! Не найден такой пункт в меню" << std::endl;
  51. }
  52. Print(text);
  53. }
  54. }
  55.  
  56. void CopyLine(std::vector<std::wstring>& text)
  57. {
  58. if (text.empty())
  59. {
  60. std::wcout << L"Ошибка! Текст пуст" << std::endl;
  61. return;
  62. }
  63. unsigned fromLine, beforeLine;
  64. for (;;)
  65. {
  66. std::wcout << L"\nВведите номер копируемой строки: ";
  67. if (!(std::wcin >> fromLine) || fromLine > text.size() || fromLine < 1)
  68. {
  69. std::wcin.clear();
  70. std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
  71. std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
  72. continue;
  73. }
  74. std::wcout << L"Введите номер, куда будет скопирована строка: ";
  75. if (!(std::wcin >> beforeLine) || beforeLine > text.size() || beforeLine < 1)
  76. {
  77. std::wcin.clear();
  78. std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
  79. std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
  80. continue;
  81. }
  82. break;
  83. }
  84. text.insert(text.begin() + beforeLine - 1, *(text.begin() + fromLine - 1));
  85. }
  86.  
  87. void Print(std::vector<std::wstring>& text)
  88. {
  89. if (text.empty())
  90. {
  91. return;
  92. }
  93. std::wcout << std::endl;
  94. std::wcout << L"Текст:" << std::endl;
  95. for (const auto& line : text)
  96. std::wcout << line << std::endl;
  97. }
  98.  
  99. void DeleteChars(std::vector<std::wstring>& text)
  100. {
  101. if (text.empty())
  102. {
  103. std::wcout << L"Ошибка! Текст пуст" << std::endl;
  104. return;
  105. }
  106. unsigned line, quantity;
  107. for (;;)
  108. {
  109. std::wcout << L"\nВведите номер строки: ";
  110. if (!(std::wcin >> line) || line < 1 || line > text.size())
  111. {
  112. std::wcin.clear();
  113. std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
  114. std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
  115. continue;
  116. }
  117. std::wcout << L"Введите количество символов: ";
  118. if (!(std::wcin >> quantity) || quantity > text[line].size() || quantity < 1)
  119. {
  120. std::wcin.clear();
  121. std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
  122. std::wcout << L"Ошибка! Попробуйте снова:" << std::endl;
  123. continue;
  124. }
  125. break;
  126. }
  127. text[line - 1].erase(text[line - 1].begin(), text[line - 1].begin() + quantity);
  128. }
  129.  
  130. std::wstring ReadLine()
  131. {
  132. std::wstring buffer;
  133. std::wcout << L"\nВведите строку:" << std::endl;
  134. std::wcin.clear();
  135. std::wcin.ignore(std::numeric_limits<std::streamsize>::max(), L'\n');
  136. std::getline(std::wcin, buffer);
  137. return buffer;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement