Advertisement
Guest User

Untitled

a guest
May 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <fstream>
  6. #include <io.h>
  7. #include <locale>
  8. #include <string>
  9. #include <vector>
  10. #include <limits>
  11. #include <fcntl.h>
  12.  
  13. using namespace std;
  14.  
  15. void selection(vector<wstring>& text);
  16. void addbegin(vector<wstring>& text, wstring& buffer);
  17. void addend(vector<wstring>& text);
  18. void copy(vector<wstring>& text);
  19. void print(vector<wstring>& text);
  20.  
  21. int main()
  22. {
  23. _setmode(_fileno(stdout), _O_WTEXT);
  24. _setmode(_fileno(stdin), _O_WTEXT);
  25. vector<wstring> text;
  26. wstring buffer;
  27. while (true)
  28. {
  29. wcin.ignore();
  30. wcout << L"Введите строку:" << endl;
  31. getline(wcin, buffer);
  32. }
  33.  
  34. text.push_back(buffer);
  35. wcout << endl;
  36. while (true)
  37. {
  38. wcout
  39. << L"Выберите действие:\n"
  40. << L"1. Вставка в начало\n"
  41. << L"2. Отбор (с N до M символа)\n"
  42. << L"3. Копирование строк\n"
  43. << L"4. Добавить строку к тексту\n"
  44. << L"5. Выход\n";
  45. m: int i = -1;
  46. wcin >> i;
  47. switch (i)
  48. {
  49. case 1:
  50. addbegin(text, buffer);
  51. break;
  52. case 2:
  53. selection(text);
  54. break;
  55. case 3:
  56. copy(text);
  57. break;
  58. case 4:
  59. addend(text);
  60. break;
  61. case 5:
  62. return 0;
  63. default:
  64. wcout << L"Ошибка! Введите снова:" << endl;
  65. wcin.clear();
  66. wcin.ignore();
  67. goto m;
  68. }
  69. }
  70. }
  71.  
  72. void addend(vector<wstring>& text)
  73. {
  74. wstring buffer;
  75. wcout << L"\nВведите cтроку:" << endl;
  76. wcin.ignore();
  77. getline(wcin, buffer);
  78.  
  79. text.emplace_back(buffer);
  80. print(text);
  81. }
  82.  
  83. void copy(vector<wstring>& text)
  84. {
  85. m1: int from = 0, to = 0;
  86. wcout << L"\nКопировать строку номер: ";
  87. wcin >> from;
  88. wcout << L"Перед строкой номер: ";
  89. wcin >> to;
  90. if (from < 1 || to < 1 || from > text.size() || to > text.size())
  91. {
  92. wcout << L"Ошибка" << endl;
  93. wcin.clear();
  94. wcin.ignore();
  95. goto m1;
  96. }
  97. from--;
  98. to--;
  99. text.insert(text.begin() + to, text[from]);
  100. print(text);
  101. }
  102.  
  103. void selection(vector<wstring>& text)
  104. {
  105. m2: int str = 0, N = 0, M = 0;
  106. wcout << L"\nВведите номер строки: ";
  107. wcin >> str;
  108. wcout << L"Отбор с символа номер: ";
  109. wcin >> N;
  110. wcout << L"До символа номер: ";
  111. wcin >> M;
  112. wcout << endl;
  113. if (str < 1 || str > text.size() || N < 1 || N > text[str - 1].length() || M < 1 || M > text[str - 1].length())
  114. {
  115. wcout << L"Ошибка" << endl;
  116. wcin.clear();
  117. wcin.ignore();
  118. goto m2;
  119. }
  120. str--;
  121. N--;
  122. M--;
  123. wcout << L"Результат:" << endl;
  124. for (int i = N; i <= M; i++)
  125. wcout << text[str][i];
  126. wcout << "\n\n";
  127. }
  128.  
  129. void addbegin(vector<wstring>& text, wstring& buffer)
  130. {
  131. wcout << L"\nВведите cтроку:" << endl;
  132. wcin.ignore();
  133. getline(wcin, buffer);
  134.  
  135. text.insert(cbegin(text), buffer);
  136. print(text);
  137. }
  138.  
  139. void print(vector<wstring>& text)
  140. {
  141. wcout << L"\nПолучившийся текст:" << endl;
  142. for (auto s : text)
  143. wcout << s << endl;
  144. wcout << endl;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement