Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <Windows.h> // нужна для работы SetConsole
- using namespace std;
- void InsertChar(char* str, char ch, int num) {
- num--;
- for (int i = strlen(str) + 1; i > num; i--) {
- str[i] = str[i - 1];
- }
- str[num] = ch;
- }
- int main() {
- SetConsoleCP(1251); // установка кодировки 1251 в поток ввода
- SetConsoleOutputCP(1251); // установка кодировки 1251 в поток вывода (то же, что setlocale)
- char line[40];
- char ch;
- int num;
- cout << "Введите строку: ";
- gets_s(line);
- cout << "Введите символ: ";
- cin >> ch;
- cout << "Введите позиция: ";
- cin >> num;
- InsertChar(line, ch, num);
- cout << line << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment