35657

Untitled

Jan 20th, 2024
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <Windows.h> // нужна для работы SetConsole
  5.  
  6. using namespace std;
  7.  
  8. void InsertChar(char* str, char ch, int num) {
  9.     num--;
  10.     for (int i = strlen(str) + 1; i > num; i--) {
  11.         str[i] = str[i - 1];
  12.     }
  13.     str[num] = ch;
  14. }
  15.  
  16. int main() {
  17.  
  18.     SetConsoleCP(1251); // установка кодировки 1251 в поток ввода
  19.     SetConsoleOutputCP(1251); // установка кодировки 1251 в поток вывода (то же, что setlocale)
  20.  
  21.     char line[40];
  22.     char ch;
  23.     int num;
  24.  
  25.     cout << "Введите строку: ";
  26.     gets_s(line);
  27.     cout << "Введите символ: ";
  28.     cin >> ch;
  29.     cout << "Введите позиция: ";
  30.     cin >> num;
  31.     InsertChar(line, ch, num);
  32.     cout << line << endl;
  33.    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment